1

我正在使用版本 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);
        }
    }
4

1 回答 1

1

根据我的经验,您需要在模拟器中添加一个 google 帐户。

您只能使用 Google API 8 的目标来执行此操作,而不是 Android 2.2。

于 2010-09-27T05:59:39.330 回答