Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to simulate a GCM receive from the adb shell / am command line? I'm getting an error

Tags:

I'm trying to simulate as if the device is receiving a GCM push message by using adb and the command line. I've tried this command to broadcast a GCM intent:

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

This triggers a "Permission denial" log line though:

09-19 12:23:34.820      725-787/? W/BroadcastQueue﹕ Permission Denial: broadcasting Intent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.myapp] flg=0x10 (has extras) } from null (pid=21244, uid=2000) requires com.google.android.c2dm.permission.SEND due to receiver com.myapp/com.google.android.gcm.GCMBroadcastReceiver 

Relevant parts of my manifest:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <application> <receiver     android:name="com.google.android.gcm.GCMBroadcastReceiver"     android:permission="com.google.android.c2dm.permission.SEND" >     <intent-filter>         <action android:name="com.google.android.c2dm.intent.RECEIVE" />         <action android:name="com.google.android.c2dm.intent.REGISTRATION" />         <category android:name="com.myapp" />     </intent-filter> </receiver> </application> 

Any ideas?

Edit / clarification: Push / GCM receive works in production. I'm looking for an easier way to test changes.

like image 551
Nilzor Avatar asked Sep 19 '14 10:09

Nilzor


People also ask

How do I run adb from command line?

Open a command window in the folder by holding shift and right-clicking in an empty spot in the folder and selecting "Open command prompt/PowerShell here" in the menu. Then you can start using ADB — connect your phone and try . ADB devices to see if it's working. A list with attached devices should show up.

Can I Enable USB debugging using adb?

To use adb with a device connected over USB, you must enable USB debugging in the device system settings, under Developer options. To use adb with a device connected over Wi-Fi, see Connect to a device over Wi-Fi. On Android 4.2 and higher, the Developer options screen is hidden by default.

How do I know if adb is working?

If you're already on Ice Cream Sandwich, go to Settings > Developer options and tick “Android debugging” or “USB debugging.” A result like that (where the X's represent your device's actual serial number) confirms that your ADB is set up and working.


1 Answers

You need to remove the permission property in your receiver's definition like this:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <application> <receiver     android:name="com.google.android.gcm.GCMBroadcastReceiver" >     <intent-filter>         <action android:name="com.google.android.c2dm.intent.RECEIVE" />         <action android:name="com.google.android.c2dm.intent.REGISTRATION" />         <category android:name="com.myapp" />     </intent-filter> </receiver> </application> 
like image 91
guy.gc Avatar answered Sep 18 '22 20:09

guy.gc