我正在使用版本 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 APIs 8 而不是 Android 2.2 执行此操作。
关于android - 使用 C2DM 注册 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3757576/