Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save moneer-muntazah/90bb4686ffa1aa31f7ce5efa9a8c3586 to your computer and use it in GitHub Desktop.
Save moneer-muntazah/90bb4686ffa1aa31f7ce5efa9a8c3586 to your computer and use it in GitHub Desktop.
This gist explains how to send push notification locally using ADB without need network connection.

Requirements:

  • Device should be a rooted (simulator’s are rooted by default)

  • adbd should be started as root. (Rub command: adb root )

Now, send local push message using command:

adb shell am broadcast \
  -n com.your.app/com.google.firebase.iid.FirebaseInstanceIdReceiver \
  -a "com.google.android.c2dm.intent.RECEIVE" \
  --es "extra1" "65" \
  --es "guid" "1f400184-9215-479c-b19a-a9cd9a1d9dc9" \
  --es "extra3" "VALUE" \
  --es "extra4" "'Long string with spaces'"

What’s happening?

  • Simply, using adb we are broadcasting message with parameters.

  • adb shell am broadcast command that broadcasts.

  • -n parameter for define component (see IntentSpec@ADB Documentation)

  • We are broadcasting for com.google.firebase.iid.FirebaseInstanceIdReceiver, because we are using Firebase Messaging Service

  • We are sending action -a com.google.android.c2dm.intent.RECEIVE because FirebaseInstanceIdReceiver defines this in AndroidManifest.xml file.

    • Also, this is why we need to be root. This action requires Signature level permission.

  • We are adding extras with --es parameter.

Now, we can get data in onMessageReceived under the FirebaseMessagingService. When user taps notification remoteMessage.getData().get("extra1") should be return "65".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment