Problem Registration for C2DM in Android

I am trying to check the structure of C2DM. I received a confirmation email a couple of days ago, and then tried to create a client that could register. For this purpose, I created a simple client by following the steps described in this lesson: http://code.google.com/intl/es-419/android/c2dm/index.html .

The Android manifest file contains, among other things, this code:

<permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.INTERNET"/> <receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.bilthon.ufrj" /> </intent-filter> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.bilthon.ufrj" /> </intent-filter> </receiver> 

And then the main activity launched at program startup has the following code:

 Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate registrationIntent.putExtra("sender"," mytestemail@gmail.com "); Log.d("WelcomeScreen"," mytestemail@gmail.com "); startService(registrationIntent); 

I also registered a google account on AVD, which is running my client, as they said it was necessary. But the problem is that I can’t get the broadcast receiver to wake up. I do not know what might be wrong. By analyzing the logs, I see that the intent of the registration is created and apparently used correctly, but the recipient code just never executes, what could be wrong?

Thanks in advance Nelson

+6
android android-manifest android-c2dm
source share
4 answers

Well .. just figured it out, the problem was the receiver’s declaration. Tags for the receiver should be inside the application tag, as shown in the image: http://developer.android.com/guide/topics/manifest/manifest-intro.html

Here is an example of a well-formed manifest for a C2DM application. Thanks to Mark Murphy for posting the link in the android-c2dm group.

And sorry for the stupid mistake.

Nelson

+9
source share

I just got this job after struggling with it for some time.

In the manifest you have a line

 <receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND"> 

This means that you need a class called C2DMReceiver that extends C2DMBaseReceiver in the c2dm package. To implement this, I copied both the c2dm package and the C2DMReceiver.java file from the chrometophone-android example into my project and was able to get the registration ID from the C2DM server, as expected.

+3
source share

I had the same problem. My solution moved all permissions in my manifest above the application tag.

+2
source share

Things you can check:

1 I noticed that you are declaring C2DM permission, but not using it in your application like this:

 <uses-permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" /> 

2 If you look at the c2dm library, you will see that the C2DMessaging register C2DMessaging creates an intent with an additional setPackage call.

 registrationIntent.setPackage("com.google.android.gsf"); 
+1
source share

All Articles