GCM Broadcast Receivers

So I worked with Pubnub and GCM. Although this question is more GCM / Android than Pubnub. I have 2 apps - one is mine, the other is a pubnub example.

Pubnub manifest receiver tag:

<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>

      

My app receiver tag:

<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>

      

Apparently the broadcast receiver of the pubnub app is getting a call, but not the one I have. Both of them have 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" />

      

Infact mine has even more.

What could I be doing wrong that my own app listener isn't called by GCM when a notification is sent through it? My guess was that since it was streaming multiple apps with similar receivers, they could get them?

Note. This is not really a requirement in my work, but testing and trying to understand how this concept works.

+1


source to share


2 answers


One of the problems I see is that the category tag in your AndroidManifest file needs to be updated to your package name.



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

      

+1


source


When your app registers with GCM, it uses sender_id and GCM returns register_id. I believe the registration_id will be unique for each application. You can check this by examining the register_id that is returned when each application supports GCM. If you want the message to be delivered to both applications, you need to send it to both registration files



0


source







All Articles