In order to implement GCM correctly, a com.google.android.c2dm.SEND
permission should be specified for the receiver as per the official docs:
The receiver should require the com.google.android.c2dm.SEND permission, so that only the GCM Framework can send a message to it.
When I add that permission however, I get this error when a message is received.
W/GTalkService(25224): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.XXX.XXX] (has extras) }
followed by this error:
W/ActivityManager(283): Permission Denial: broadcasting Intent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.XXX.XXX] flg=0x10 (has extras) } from com.google.android.syncadapters.contacts requires com.google.android.c2dm.SEND due to receiver com.XXX.XXX/com.XXX.XXX.GcmBroadcastReceiver
If I remove that permission only, without changing anything else, the receiver works normally and I can process the message.
and here's the receiver definition in AndroidManifest.xml
<receiver
android:name="com.XXX.XXXX.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.XXX.XXX" />
</intent-filter>
</receiver>
I'm using the debug certificate during testing, in case that might be relevant.