Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.