Created
March 19, 2024 15:35
-
-
Save sigmadeltasoftware/7f367894b7195ae539e9d9b7c7a6dbd3 to your computer and use it in GitHub Desktop.
Send mock push notifications to a locally (rooted) device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- NOTE: REPLACE THE CATEGORY WITH YOUR OWN PACKAGE NAME --> | |
<!-- Don't include this receiver in your main AndroidManifest as it's a security hazard --> | |
<receiver | |
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" | |
android:exported="true" | |
android:permission="@null" | |
tools:replace="android:permission"> | |
<intent-filter> | |
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> | |
<category android:name="some.randome.packagename" /> | |
</intent-filter> | |
</receiver> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Use this script to emulate push notifications | |
# This only works on rooted devices (f.e. Emulators are rooted by default). Once the emulator is started, | |
# execute following command to make sure these commands are executed as root as well (without $): | |
# $ adb root | |
# Here's an example of a single notification to post in CLI: | |
## You can add/modify a link to the list by following the structure of KEY::VALUE | |
# Where KEY will be the title of the push notification and value will be the actual | |
# push notification & body | |
links=( | |
"Push_notification_title::https://www.mydeeplinkurl.com/this/is/a/deeplink" | |
) | |
# DON'T FORGET TO CHANGE THE PACKAGENAME AFTER THE -n TO YOURS AS WELL | |
# The deeplink URL can be extracted from your app by getting the "deeplink" extra from the intent (`intent.extras.getString("deeplink")`) | |
for key in "${links[@]}" ; do | |
KEY="${key%%::*}" | |
VALUE="${key##*::}" | |
echo "Triggering: $VALUE" | |
adb shell am broadcast \ | |
-n some.randome.packagename/com.google.firebase.iid.FirebaseInstanceIdReceiver \ | |
-a "com.google.android.c2dm.intent.RECEIVE" \ | |
--es "gcm.n.e" "1" \ | |
--es "gcm.n.title" "$KEY" \ | |
--es "gcm.n.body" "$VALUE" \ | |
--es "deeplink" "$VALUE" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment