向C2DM注册Android应用
作者:互联网
我正在使用版本8的模拟器,当我尝试注册Android应用程序时,它将提供空注册ID.请帮助我解决此问题.我该如何向C2DM注册Android应用程序.我的代码是注册该应用程序.
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(startCode.this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender", "12786@gmail.com");
startService(registrationIntent);
handleRegistration(getApplicationContext(), registrationIntent);
private void handleRegistration(Context context, Intent intent) {
String registration = intent.getStringExtra("registration_id");
if (intent.getStringExtra("error") != null) {
// Registration failed, should try again later.
Log.e("ERROR", "ERROR");
} else if (intent.getStringExtra("unregistered") != null) {
// unregistration done, new messages from the authorized sender will be rejected
Log.e("unregistered", "unregistered");
} else if (registration != null) {
// Send the registration ID to the 3rd party site that is sending the messages.
// This should be done in a separate thread.
// When done, remember that all registration is done.
Log.e("registration", registration);
}
}
解决方法:
根据我的经验,您需要在模拟器中添加一个Google帐户.
您只能使用Google API 8的目标,而不能使用Android 2.2.
标签:android,push-notification,android-c2dm 来源: https://codeday.me/bug/20191009/1878913.html