How to send FCM (firebase cloud messaging) push notification from ADB to the device

We use firebase cloud messaging to receive push notifications in the Android application.

Currently, to test push notifications, we need to send a message to the FCM server and wait for the message to appear on the device. Most of the time, the device receives a lot of time to receive a notification from the FCM server.

Listed below are some links explaining how to send a push notification to a device using the adb broadcast command (this example explains how to send a message using the GCM environment, but we use FCM) Is it possible to simulate GCM receipt from the adb shell / am command line? I get an error

Is there a similar way to send push notifications using adb to a device with FCM?

+16
android adb firebase firebase-cloud-messaging google-cloud-messaging
source share
2 answers

This worked for me on an emulator (you do not need either a server key or a client token).

Run these commands on the AS terminal:

  • adb root β†’ to get permission com.google.android.c2dm.intent.RECEIVE

  •  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 to the fields in the data node:

 { "data": { "title": "Title", "body": "Body" }, "to" : "" } 
+5
source share

Unable to send push notification from adb command. Therefore, your process must be authorized to send the broadcast via ADB. But Google does not allow setting permission com.google.android.c2dm.permission.SEND .

 If you run below command and try to grant send permission to your package. ./adb shell pm grant com.example.hunted "com.google.android.c2dm.permission.SEND" 

You will get the following exception

eration not allowed: java.lang.SecurityException: Package com.example.hunted has not requested permission com.google.android.c2dm.permission.SEND

and even if you add this permission to your package

 ./adb shell pm grant com.example.hunted com.google.android.c2dm.permission.SEND Operation not allowed: java.lang.SecurityException: Permission com.google.android.c2dm.permission.SEND is not a changeable permission type. 

Finally, when sending the broadcast using adb. you will get the following exception.

 BroadcastQueue: Permission Denial: broadcasting Intent { flg=0x400010 cmp=com.example.hunted/com.google.firebase.iid.FirebaseInstanceIdReceiver (has extras) } from null (pid=32279, uid=2000) requires com.google.android.c2dm.permission.SEND due to receiver com.example.hunted/com.google.firebase.iid.FirebaseInstanceIdReceiver 
0
source share

All Articles