Application doesnt get my C2DM message?
Here is my C2DMReceiver:
public class C2DMReceiver extends C2DMBaseReceiver {
public C2DMReceiver() {
// Email address currently not used by the C2DM Messaging framework
super("dummy@gmail.com");
}
@Override
public void onRegistered(Context context, String registrationId)
throws java.io.IOException {
// The registra开发者_如何学PythontionId should be send to your applicatioin server.
// We just log it to the LogCat view
// We will copy it from there
Log.e("C2DM", "Registration ID arrived: Fantastic!!!");
Log.e("C2DM", registrationId);
};
@Override
protected void onMessage(Context context, Intent intent) {
Log.e("C2DM", "Message: Fantastic!!!");
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (extras != null) {
System.out.println(extras.get("payload"));
// Now do something smart based on the information
}
}
@Override
public void onError(Context context, String errorId) {
Log.e("C2DM", "Error!");
}
}
What it should do is show "Message: Fantastic!!!" in the LogCat but it is no where to be seen. What am I doing wrong? I have the registration ID in my web application (written in PHP) but no luck. I get this back when i execute the request:
id=0:1311936686518981%48da2b9fb207fa19
Using guide: http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
There's a lot of things you need to deal with when using C2DM. I think your code looks okay (even though I haven't test it yet). What about your AndroidManifest.xml
? I've spent almost two days just to realize that my AndroidManifest.xml
contains some errors so I couldn't make it work.
Read this documentation thoroughly and I suggest you to install (and learn from the source code, of course) the ChromeToPhone
app so you know the key to C2DM here.
And don't forget that C2DM only works for Froyo (2.2) and up.
精彩评论