1

バージョン 8 のエミュレーターを使用しています。Android アプリケーションを登録しようとすると、null 登録 ID が返されます。この問題を解決するのを手伝ってください。Android アプリケーションを C2DM に登録するにはどうすればよいですか。私のコードは、アプリケーションを登録することです。

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 アカウントを追加する必要があります。

これは、Android 2.2 ではなく、Google API 8 のターゲットでのみ行うことができます。

于 2010-09-27T05:59:39.330 に答える