Google Cloud Messaging register AUTHENTICATION_FAILED

后端 未结 3 462
萌比男神i
萌比男神i 2020-12-18 22:00

I want to try Google Cloud Messaging (GCM) service, and I am faced with a problem at the beginning.

I get an error AUTHENTICATION_FAILED while trying t

3条回答
  •  我在风中等你
    2020-12-18 22:47

    So it looks like the solution to avoid this problem is to fall back to the old deprecated GCM client library in case the AUTHENTICATION_FAILED error happens on FROYO and GINGERBREAD.

    Here is a simple code snippet of how I upgraded the new Gcm client to fallback to use the old client:

    @Override
    protected void onPostExecute(Integer resultCode) {
    
        if(resultCode == EXCEPTION_THROWED) {
    
            //Android 2.2 gmc bug http://stackoverflow.com/questions/19269607/google-cloud-messaging-register-authentication-failed
    
            //fall back to old deprecated GCM client library
    
            GCMRegistrar.checkDevice(StartActivity.this);
            GCMRegistrar.checkManifest(StartActivity.this);
            final String registrationId = GCMRegistrar.getRegistrationId(StartActivity.this);
            if (registrationId.equals("")) {
                GCMRegistrar.register(StartActivity.this, SENDER_ID);
            }
    
            //Toast.makeText(context, "Orders and menus won't be sync with other devices since GoogleCloudMessaging is not working correctly on this device. Please notify the developer.", Toast.LENGTH_LONG).show();
    
        }
    
    }

    You can find the old deprecated GCM Client helpher here: http://developer.android.com/google/gcm/helper.html

    You can find the code of the GCM client on your computer on the path: ANDROID_SDK_ROOT/extras/google/gcm-client (given you've downloaded this extra using the Android SDK Manager).

    I put the old gcm client in a new package named com.google.android.gcm.deprecated to try to remember myself to not use this for other stuff.

提交回复
热议问题