GCM 'Error : Not Registered'

2019-01-07 16:03发布

问题:

I succeed in testing My GCM code.

But exactly same code, I couldn't get GCM push and got:

GCM Error : Not Registered.

回答1:

GCM response Not Registered means following "If it is NotRegistered, you should remove the registration ID from your server database because the application was uninstalled from the device or it does not have a broadcast receiver configured to receive com.google.android.c2dm.intent.RECEIVE intents." from documentation. Check in what case you get this error, when app is uninstalled from the device or you describe incorrect broadcast receiver in AndroidManifest. You can test your GCM functionality with my test GCM server. Hope, this helps you.



回答2:

If you are using a device for testing, you need to delete the InstanceID before obtaining the token and re-testing because once you overwrite your APK it de-registers that InstanceId and you get that NotRegistered error. So in your RegisterIntentService class, in the onHandleIntent function do the following:

InstanceID instanceID = InstanceID.getInstance(this);
try
{
    instanceID.deleteInstanceID();
} catch(IOException e) 
{
    e.printStackTrace();
}
instanceID = InstanceID.getInstance(this);


回答3:

The Not Registered happens when GCM thinks the device could not handle the message. This happens if the app is uninstalled or misconfigured to handle the message:

Based on @Samik and @O'Rilla answers I would suggest following steps:

  1. Uninstall the current installation from Android device
  2. Make sure you have <receiver> and <sender> are defined in <application> node in AndroidManifest.xml.
  3. Make sure you have the correct <category android:name="COM.COMPANY.YOURAPP" /> in your <receiver>
  4. Make sure the implementation of Receiver is right


回答4:

If you really think your code is correct and still getting error

{"error": "NotRegistered"} 

try un-installing app manually from phone and run it again (your device will get new registration ID).

At least in my case the problem was solved!



回答5:

I had this error when I had the gcm receiver outside of the application in the manifest file. Moved the receiver into the application scope and everything worked. A very happy bunny now.

<application>
...
<receiver>
...
</receiver>
...
</application>


回答6:

I was using the old deprecated code for GCM:

if (gcm == null) {
                gcm = GoogleCloudMessaging.getInstance(this);
            }
            String regId = gcm.register(SENDER_ID);
            msg = "Device registered, registration ID=" + regId;

and when trying to switch to the new way:

InstanceID instanceID = InstanceID.getInstance(this);
            String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

I was getting the same error and it was driving me nuts for two solid days.

After trying everything in the book what fixed it was disabling GCM in the developers console, re-enabling it, then going here: https://developers.google.com/mobile/add to generate a new google-services.jsonfile for my Android app.

Also note, the RegistrationIntentService must be at the root of your package or it won't work! (see this sample for gcm implementation into Android: https://github.com/google/gcm)

Hope this helps someone because I lost days on this!!!! ><



回答7:

A Google account is a requirement on devices running Android 4.0.4 or lower. http://developer.android.com/google/gcm/gcm.html

You should also add <uses-permission android:name="android.permission.GET_ACCOUNTS" /> in your manifest file.



回答8:

This means simply your are giving a wrong registration Id. So for this, first run your mobile application and your registration ID will come as token. Put this token to your app server code as registration ID. For App ID give server ID, which you could get from Google developer console,your project,And credentials. For sender Id , set your project ID which could aquire from project,settings in developer console.