1
我正在使用版本8的模拟器,当我尝试注册Android应用程序时,它会给出空注册ID。请帮我解决这个问题。我如何使用C2DM注册Android应用程序。我的代码是注册App。使用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", "[email protected]");
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 API 8,并且我已经在模拟器中创建帐户,但是如何将通知发送到我的模拟器 – 2010-09-27 07:07:20
注册过程完全自动化并且在模拟器中正常工作。如上所述,您需要设置一个Google帐户,但是您的注册码应该会导致注册响应(从而导致C2DM ID)。如果你没有收回ID,那么你错过了其他的东西(一个许可,也许?check logcat)。 – mbafford 2011-03-07 14:32:22
通过C2DM通道向模拟器发送“通知”仍然需要Google服务器才能正常工作。没有“模拟”C2DM消息选项,您必须使用此处列出的说明通过Google服务器发送一个:http://code.google.com/android/c2dm/index.html#server – mbafford 2011-03-07 14:34:56