Search code examples
androidandroid-c2dm

Android - Cannot receive C2DM Registration Intent


I am attempting to register my device with C2DM and am having major issues. I have followed several tutorials, all of which are very similar. I believe the issue has to do with the registration intent that it sends to the C2DM server. Does anyone have any suggestions. The following is the relevant code:

Manifest: The permissions (outside my application tag):

<!-- Used for C2DM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.companyname.parade.permission.C2D_MESSAGE" />

This is the Intent registration (inside my application tag):

<receiver
    android:name=".C2DMReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >
    <!-- Receive the actual message -->
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />

        <category android:name="com.companyname.parade" />
    </intent-filter>
    <!-- Receive the registration id -->
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="com.companyname.parade" />
    </intent-filter>
</receiver>

The following is what I call to register my device to the C2DM server (it starts the service that contacts the C2DM servers that is suppose to send back a registration Intent with my registartionID in it). It is located in a file called C2DMessaging:

public static void register(Context context) {
    Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
    registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
            PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    registrationIntent.putExtra(EXTRA_SENDER, SENDER_ID);
    ComponentName name = context.startService(registrationIntent);
    if(name == null){
        // FAIL!
        Log.d(TAG, "FAIL");
    }else{
        // SUCCESS
        Log.d(TAG, "Success");
    }
}

The ComponentName info is the following:

com.google.android.gsf/com.google.android.gsf.gtalkservice.PushMessagingRegistrar

There is no logcat output. My receiver (named C2DMReceiver) is the following:

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (C2DMessaging.INTENT_REGISTRATION_CALLBACK.equals(action)) {
        // Registration Intent
        Log.w(TAG, "Registration Receiver called");
        handleRegistration(context, intent);
    } else if (action.equals(C2DMessaging.INTENT_RECEIVED_MESSAGE_CALLBACK)) {
        Log.w(TAG, "Message Receiver called");
        handleMessage(context, intent);
    } else if (action.equals(C2DMessaging.INTENT_C2DM_RETRY)) {
        C2DMessaging.register(context);
    }
}

This does not get called at all.

Edit: This whole thing was a stupid mistake on my part. I simply forgot a step somehow in the tutorials I read. I need to add this to my permissions:

<permission android:name="com.companyname.parade.permission.C2D_MESSAGE" android:protectionLevel="signature" />

Thanks to MisterSquonk for the response.


Solution

  • From the Google docs for C2DM for Creating the Manifest, the manifest needs a <permission> entry to complement the <uses-permission> entry for C2D_MESSAGE.

    Something like this...

    <permission android:name="com.companyname.parade.permission.C2D_MESSAGE" android:protectionLevel="signature" />