android - 使用 C2DM 注册 Android 应用程序

标签 android push-notification android-c2dm

我正在使用版本 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/

相关文章:

安卓数据绑定(bind) : Layout to the view

c# - 从 WCF 返回 IObservable<T>

Android C2DM ROLE 账号和包名

android - 自定义 android 微调器

java - Android-显示自定义对话框

php - 为什么在 android 中计算与在 php 中不同?

Firefox 通知返回 InvalidRegistration FCM

android - 当您将 Android API < 8 注册到 C2DM 时会发生什么?

android - C2DM 上的验证码

Android:如何从 C2DMBaseReceiver 调用非静态函数?