【问题标题】:GCM Broadcast ReceiversGCM 广播接收器
【发布时间】:2014-12-05 12:59:17
【问题描述】:

所以我一直在使用 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 调用,我可能做错了什么?我的期望是,由于它是广播,因此具有相似接收器的多个应用程序会收到它们?

注意:这并不是我工作中的真正要求,而是测试并尝试了解此概念的工作原理。

【问题讨论】:

    标签: android android-intent google-cloud-messaging pubnub


    【解决方案1】:

    我看到的一个问题是您的 AndroidManifest 文件中的类别标签必须更新为您的包名称。

    <category android:name="com.myapp.app." />
    

    【讨论】:

    • 这只是我的包名。为了这个问题,我只是将其更改为com.myapp.app
    【解决方案2】:

    当您的应用向 GCM 注册时,它使用一个 sender_id,而 GCM 返回一个 registration_id。我相信registration_id对于每个应用程序都是唯一的。您可以通过检查每个应用程序使用 GCM 抵抗时返回的 registration_id 来检查这一点。如果您希望将消息发送到两个应用程序,那么您需要将其发送到两个registration_ids

    【讨论】:

      猜你喜欢
      • 2015-06-28
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多