We are using firebase cloud messaging to get the push notification into android app.
Currently to test push notification we need to send the message to FCM server and wait for the message to arrive to device. Most of the time device is taking long time get the notification from FCM server.
I can see some links below which explains sending push notification to device using adb broadcast command (This example explains sending message using GCM framework, but we use FCM) Is it possible to simulate a GCM receive from the adb shell / am command line? I'm getting an error
Is there any similar way to send push notification using adb to device which have FCM?
For sending FCM notification payload you can use Firebase Cloud Messaging Tool in firebase console. And click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token.
It worked for me on the emulator (you need neither server key nor client token).
Run these commands on the AS terminal:
adb root
-> In order to get the com.google.android.c2dm.intent.RECEIVE
permission
adb shell am broadcast \
-n <YOUR.APP.PACKAGE>/com.google.firebase.iid.FirebaseInstanceIdReceiver \
-a "com.google.android.c2dm.intent.RECEIVE" \
--es "title" "Title" \
--es "body" "Body"```
where the --es
fields correspond with the fields within data
node:
{
"data": {
"title": "Title",
"body": "Body"
},
"to" : ""
}
It is possible to send FCM payloads via adb.
while it is true that the permission com.google.android.c2dm.permission.SEND
is a problem, there's a workaround.
gradle adds the FirebaseInstanceIdReceiver
to the merged manifest. the workaround is to add your own copy to the manifest and override the permission
using the tools:replace="android:permission"
and android:permission="@null"
<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="your.package.name" />
</intent-filter>
</receiver>
then issue
adb shell "am broadcast -n your.package.name/com.google.firebase.iid.FirebaseInstanceIdReceiver -c your.package.name -a com.google.android.c2dm.intent.RECEIVE ...
via the terminal
(PS - I highly recommend doing it only in debug builds either via gradle's manifest placeholder or a seperate AndroidManifest.xml in your debug/develop builds)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With