简体   繁体   中英

Receiving push notifications using adb shell command

I am trying to receive push notifications on my device, using the below adb shell command:

adb shell am broadcast -c com.xxxx.android -a com.google.android.c2dm.intent.RECEIVE -e data "Data"

But I am not receiving any push messages or errors.

This is the output I get:

Intent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.myapp] (has extras) } Broadcast completed: result=0

Here is the basic use of adb broadcast command:

adb shell am broadcast
-a <INTENT_NAME>
-n <PACKAGE_NAME>/<RECEIVER_NAME>
[--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...]]

And you can find the RECEIVER_NAME in your AndroidManifest.xml :

<receiver
    android:name="foo.bar.SomeBroadcastReceiver"
    android:exported="true"
    android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="xyz.abc" />
    </intent-filter>
</receiver>

Example command:

adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE -n <YOUR_PACKAGE_NAME>/<YOUR_RECEIVER_NAME> --es "<EXTRA_KEY>" "<EXTRA_VALUE>"

Use should use key -n instead -c .

Key -c is category key.

    [-c <CATEGORY> [-c <CATEGORY>] ...]

Use command:

 adb shell am broadcast -m com.myapp -a com.google.android.c2dm.intent.RECEIVE -e key "data"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM