所以我一直在与Pubnub和GCM合作。虽然这个问题比Pubnub更具GCM / Android特性。我有2个应用程序 - 一个是我自己的,另一个是pubnub的例子。
Pubnub清单的接收者标签:
<receiver
android:name="com.pubnub.pubnubexample.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
我的应用程序的接收器标签:
<receiver
android:name="com.myapp.app.MyReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
显然,pubnub示例应用程序的广播接收器确实被调用但不是我的那个。它们都有uses-permission
:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
事实上我的还有更多。
当我通过它发送通知时,GCM会调用我自己的应用程序的接收者,我可能做错了什么?我的期望是,因为广播多个具有类似接收器的应用会收到它们吗?
注意:这不是我工作中的一项要求,而是测试并尝试理解这个概念的工作原理。
答案 0 :(得分:1)
我可以看到的一个问题是AndroidManifest文件中的类别标记必须更新为您的包名。
<category android:name="com.myapp.app." />
答案 1 :(得分:0)
当您的应用向GCM注册时,它使用a sender_id,GCM返回registration_id。我相信registration_id对每个应用程序都是唯一的。您可以通过检查每个应用程序使用GCM阻止时返回的registration_id来检查这一点。如果您希望将邮件传递给两个应用程序,则需要将其发送到registration_ids