无法注册GCM

时间:2016-11-13 10:11:51

标签: android push-notification google-cloud-messaging firebase-cloud-messaging amazon-sns

我尝试在Android应用上基于GCM推送服务初始化SNS推送服务。该应用程序在我以前的设备,三星Galaxy S5上运行良好。最近,我把手机换成了小米Redmi 3S Prime。我第一次在新手机上安装了这个错误日志:

E/GCMTokenHelper: Unable to register with GCM. MAIN_THREAD
                                                             java.io.IOException: MAIN_THREAD
                                                                 at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
                                                                 at com.google.android.gms.iid.InstanceID.getToken(Unknown Source)
                                                                 at com.amazonaws.mobile.push.GCMTokenHelper.updateGCMToken(GCMTokenHelper.java:79)
                                                                 at com.amazonaws.mobile.push.PushManager.registerDevice(PushManager.java:202)
                                                                 at com.intap.appme.HomeActivity.onCreate(HomeActivity.java:237)
                                                                 at android.app.Activity.performCreate(Activity.java:6303)
                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
                                                                 at android.app.ActivityThread.access$900(ActivityThread.java:153)
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5441)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

这些行包含日志中提到的错误:
GCMTokenHelper.java:79

synchronized
public void updateGCMToken() {
    String newDeviceToken;
    // GCM throws a NullPointerException in some failure cases.
    try {
        /* This is 79 line which gives me error -> */ newDeviceToken = instanceID.getToken(gcmSenderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
    } catch (final Exception re) {
        final String error = "Unable to register with GCM. " + re.getMessage();
        Log.e(LOG_TAG, error, re);
        for (GCMTokenUpdateObserver observer : updateObservers) {
            observer.onGCMTokenUpdateFailed(re);
        }
        return;
    }

    Log.d(LOG_TAG, "Current GCM Device Token:" + newDeviceToken);

    final boolean didTokenChange = !newDeviceToken.equals(deviceToken);
    if (didTokenChange) {
        Log.d(LOG_TAG, "GCM Device Token changed from: " + deviceToken);
        deviceToken = newDeviceToken;
        sharedPreferences.edit()
            .putString(SHARED_PREFS_KEY_DEVICE_TOKEN, deviceToken)
            .apply();
    }
    for (GCMTokenUpdateObserver observer : updateObservers) {
        observer.onGCMTokenUpdate(deviceToken, didTokenChange);
    }
}

PushManager.java:202

public void registerDevice() {
    // Updates the GCM token, which triggers {@link #onGCMTokenUpdate(String,boolean)} to create the platform
    // arn set push enabled, and re-subscribe to any previously subscribed topics.
    /* This is line 202 which gives me error -> */ gcmTokenHelper.updateGCMToken();
}

HomeActivity.java:237

final PushManager pushManager = AWSMobileClient.defaultMobileClient().getPushManager();

    pushManager.registerDevice();

我该怎么办?在我以前的设备上它运行良好,但现在当我尝试将我的设备注册到GCM推送服务时出现错误。

0 个答案:

没有答案