Debug FCM (Firebase Cloud Messaging Notifications) using ADB

Raunak Sett
2 min readJan 31, 2019

--

To test notifications using firebase cloud messaging we always need to send a notification from the firebase console to trigger the remote notification. Which can take some time to arrive on the device, as a developer when you’re working on the notifications part of your app you want to test them seamlessly with your custom data.

This method will work on emulators as you will need root access to send a broadcast fire a notification, on real devices your phone must be rooted to get the permissions.

To get permission run this command on your terminal while the emulator is connected

  • adb root

To Send the notification

  • 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"

That’s the basic’s of sending notification through adb. Let’s talk about the extra flags to set the notification extras. You can use the following flags to add extra keys to your notification data.

[--ei <EXTRA_KEY> <EXTRA_INT_VALUE>]
[--es <EXTRA_KEY> <EXTRA_STRING_VALUE>]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE>]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE>]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE>]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--e*a <EXTRA_KEY> <EXTRA_*_VALUE>[,<EXTRA_*_VALUE...]]

Sometimes we need to send JSON as extra data to our notification for that we need use the —-es flag and escape the JSON string properly

Sample JSON data passed to notification

--es "data" '{\"alert\":\"hello\ what\"\,\"event_name\":\"NORMAL\"}'

We need to keep in mind to escape spaces commas and ensure that there are no spaces in the string.

You can create a bash script to set variables and implement in your workflow whenever you need to work on those sweet notifications in your app. I’ll probably create one soon can be used

--

--