Question

This may be a weird question but, normally when I register a receiver for an action (such as sms receiving) I specify a priority value as high as possible to my application. So that my application can get sms before other applications, and I can do whatever I want (like abort broadcast) before them.

I didn't give a priority or haven't done anything special for GCM. I added uses permission for GCM Receive, and registered a receiver in manifest file.

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
.
.
.
<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" />
    </intent-filter>
</receiver>

So suppose another application also added these to its manifest file. How does GCM calls my broadcast receiver instead of other application's broadcast receiver?

Was it helpful?

Solution

Per the GCM Client Manifest Setup:

[You must add] an applicationPackage + ".permission.C2D_MESSAGE" permission to prevent other Android applications from registering and receiving the Android application's messages. The permission name must exactly match this pattern—otherwise the Android application will not receive the messages.

I.e.,

<permission android:name="com.example.app.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />

<application ...>
    <receiver
        android:name=".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.app" />
        </intent-filter>
    </receiver>
    <service android:name=".GcmIntentService" />
</application>

where com.example.app needs to be replaced with your package name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top