41

I succeed in testing My GCM code.

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

GCM Error : Not Registered.

halfer
  • 19,824
  • 17
  • 99
  • 186
LKM
  • 2,410
  • 9
  • 28
  • 53

8 Answers8

54

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.

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Samik
  • 890
  • 1
  • 8
  • 16
  • can you please tell me how to know which ids are unregistered on the server side so that i can remove them from my DB. – Sudhanshu Gaur Sep 10 '15 at 19:29
  • @DB sure, there is only one way to know when you need remove **registration id** from your database on the server. Getting "NotRegistered" error from GCM server means that registration_id which you try to use is not valid and should be removed. Also your server should be ready to process **cannonical_id** response from GCM. I explained what does **cannonical_id** means there http://stackoverflow.com/questions/26826869/regarding-canonical-ids-in-gcm-google-cloud-messaging/26827470#26827470 – Samik Sep 10 '15 at 19:35
  • @DB Also you can diagnose your **registration_id** via my test push server http://1-dot-sigma-freedom-752.appspot.com/gcmpusher.jsp – Samik Sep 10 '15 at 19:43
  • 1
    @Samik Hi, I have a weird issue with GCM in my app. In my GCMRegistrationService when I get the token from the InstanceId API, sometimes the token returned is not valid and using it gives "NotRegistered" error. This mostly happens when the user has uninstalled the app and then reinstalls again. While debugging, I then forcefully started GCMInstanceIdListener from adb and the InstanceID API gave a new token which works. So essentially, the first token I'm getting is wrong and the second one is working. Any idea about this? – akshayt23 Apr 02 '16 at 07:27
  • @user2558050 So, make sure that your client doesn't request the token too much times, it should ask just one or two (including the update App version). Second, make sure that your server correctly handles the **cannonical_id** field and replaces the old token with new one when it's necessary. One of thess factors can impact on appearing of "NotRegistered" error. Also, make sure that your server use the same token which was gotten by your client, i.e. your client should pass the token to server in reliable manner. – Samik Apr 04 '16 at 08:11
  • @Samik So I'm actually using a third party service which needs GCM to send notifications to my app, we're not using GCM from our servers. So handling this is actually becoming problematic. I'm just sending the token to the third party service and if it's invalid and a NotRegistered error is thrown, there's no way for me to become aware of it. And I'm actually not requesting a token too many times, just the first time when the app is launched, and subsequently in the `onTokenRefresh()` call. I cant seem to understand why the InstanceId API gives an invalid token. – akshayt23 Apr 04 '16 at 09:38
18

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);
Flexo
  • 87,323
  • 22
  • 191
  • 272
Rhodesie
  • 261
  • 2
  • 5
  • Do you only do this on debug builds? – Jeremy Jul 14 '16 at 15:44
  • Yes just in debug mode – Rhodesie Jul 19 '16 at 02:12
  • The reason the first copy of this was deleted by a moderator is visible to you in the comments below it. Reproduced here: "Please don't post identical answers to multiple questions. Post one good answer, then vote/flag to close the other questions as duplicates. If the question is not a duplicate, tailor your answers to the question." – halfer Dec 18 '16 at 21:47
9

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:

enter image description here

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
Roozbeh Zabihollahi
  • 7,207
  • 45
  • 39
  • Step 2 fixed mine - a silly oversight, but your answer was a time save after a couple of days of trying to find the root cause. Thanks @Roozbeh – RobbiewOnline Jul 14 '17 at 18:37
5

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!

halfer
  • 19,824
  • 17
  • 99
  • 186
naren
  • 14,611
  • 5
  • 38
  • 45
  • In my case the problem was solved as well! I tried deleting the InstanceID and trying the to send a request again. But I only succeeded when I uninstalled the app (and I did not have to delete the instanceID like I have been trying before) – Alexey Shevelyov Jan 30 '17 at 23:38
2

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>
G O'Rilla
  • 268
  • 3
  • 5
2

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!!!! ><

Micro
  • 10,303
  • 14
  • 82
  • 120
1

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.

ztan
  • 6,861
  • 2
  • 24
  • 44
1

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.

ireshika piyumalie
  • 2,226
  • 22
  • 22
  • I am using GCM over the web and have started getting this same message recently when sending some notifications (not all). Where is this registration ID that people are talking about? I am getting this message: `{"multicast_id":63135.....,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"}]` and all my manifest file looks like is: `{"gcm_sender_id": "10395...." }` – kneidels Mar 10 '19 at 11:33