Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SDK gets NotRegistered error from GCM after a few hours

The problem

I am writing and Android SDK which should receive GCM push messages from the SDK server side. After a few hours of successful push message sending, the GCM server returns an NotRegistered error:

{
    "multicast_id":6205350692941230304,
    "success":0,
    "failure":1,
    "canonical_ids":0,
    "results":
    [
        {
            "error":"NotRegistered"
        }
    ]
}

The registrationId at the client has not changed, and the server side is updated with that token.

How can I fix the registrationId problem? Is having two listeners - one in the SDK, one in the app - a problem?

Architecture

My Android SDK registers a GCM regId upon initialization, and sends that id to the server supporting the SDK.

The embracing app might (and usually do) register a GCM regId of its own. The other regId is probably sent to the embracing app's server.

The senderId of the SDK and app are different.

Implementation

Manifest

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> ...

    <receiver
        android:name="com.xxxx.xxxxx.xxxxx"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </receiver>

Registration code

protected String doInBackground(Void... params) {
    String msg = "";
    try {
        if (gcm == null) {
            gcm = GoogleCloudMessaging.getInstance(mContext);
        }
        regid = gcm.register(SENDER_ID);
        msg = "Device registered, registration ID=" + regid;
        storeRegistrationId(mContext, regid);
        listener.onGCMRegisterFinish(regid);
    } 
    catch (IOException ex) 
    {
        msg = "Error :" + ex.getMessage();
    }
    return msg;
}

This code gets the regId from the GCM Server and send it to our backend server. It is executed at the SDK initialization, and the regId is sent every time the app returns from background.

Notes

  • unregister() is not called, neither from server or client side
  • I am raising a toast with the registration id every once in a while, so I can verify it is the same between the client and the server:
Client side

enter image description here

Server side
2015-08-02 12:31:22,383 INFO - request_2145354041215926507 
                        update push token for user: XXXXXXXX,
                        push_token: ...me1GttmSRipnWsCGVUueK7e0nk
like image 809
Gilad Eshkoli Avatar asked Jul 23 '15 10:07

Gilad Eshkoli


People also ask

Why is my message not registered in GCM?

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: Make sure you have <receiver> and <sender> are defined in <application> node in AndroidManifest.xml. Show activity on this post.

How to enable Android SDK in Android Studio?

Step 1: Opening Android Studio Settings. Navigate to the File > Settings option you will get to see below dialog screen. Inside that screen. Click on Appearance and Behavior option > System Settings options and then click on the Android SDK option to get to see the below screen.

How to check if SDK is working in Gradle?

Inside this screen, you will get to see your SDK path. You can update your SDK path by clicking on the Edit option. After that select your SDK path, then click on Apply option, and then click on the OK option. Now sync your project with Gradle files to check that SDK is working fine.

How to find SDK path in Android?

Click on Appearance and Behavior option > System Settings options and then click on the Android SDK option to get to see the below screen. Inside this screen, you will get to see your SDK path.


2 Answers

Add Category with your package name to the intent-filter

  <receiver
        android:name=".xxxxx"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.xxxx" />
        </intent-filter>
    </receiver>
like image 164
user1163234 Avatar answered Oct 19 '22 17:10

user1163234


The registration ID´s generation includes not only the device but also the app and the sender ID. If I understood your architecture correctly you want to implement a GCM-client-library (your SDK) enabling your app to use GCM through your library? If that´s true make sure that you only register once

The senderId of the SDK and app are different

I assume this is the problem, you have to register each app with a sender id (e.g. XYZ) and use the SAME sender id at the server to send the notification. It is not possible to use ABC as sender id to send notifications to a device registered for sender id XYZ

like image 22
sschmid Avatar answered Oct 19 '22 15:10

sschmid