我正在使用版本8的模拟器。当我尝试注册Android应用程序时,它将提供空注册ID。请帮我解决这个问题。如何在C2DM中注册Android应用程序。我的代码是注册App。
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);
}
}
答案 0 :(得分:1)
根据我的经验,您需要在模拟器中添加Google帐户。
您只能使用Google API 8的目标,而不是Android 2.2。