0

We use GCM with multiple Android devices. A few devices (not all) which we were able to notify using GCM, are recently failing to receive the GCM trigger (GCM server returns not registered).

However, when we call getRegistrationId() on the device we get the same registration ID when it was functional.

Any idea why the server is returning not registered while the client is returning an actual ID?

lyc001
  • 777
  • 1
  • 10
  • 25
  • Make sure you implemented the `getRegistrationId` completely. Check out [here](https://github.com/google/gcm/blob/399e88c1ef5bb95395b6392f9061e45b2fb5d49a/samples/android/gcm-demo/src/main/java/com/google/android/gcm/demo/logic/InstanceIdHelper.java#L55-L98), compare it. – bjiang Nov 06 '15 at 00:40

2 Answers2

5

NotRegistered is returned by GCM if

  • If the client app unregisters with GCM.
  • If the client app is automatically unregistered, which can happen if the user uninstalls the application. For example, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
  • If the registration token expires (for example, Google might decide to refresh registration tokens, or the APNS token has expired for iOS devices).
  • If the client app is updated but the new version is not configured to receive messages.

This token should not be used again.

On the device side you should be calling InstanceID.getToken to get a new token, then send this new token to your server for sending messages to the app.

Seems like you are using legacy reg ids to send messages to your device. If so you should switch to using InstanceID tokens to send messages to the device.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33
0

use this code to get registration id using asynk task

public class MainActivity extends Activity {
    String token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new AsyncTaskRunner().execute();

    }

    private class AsyncTaskRunner extends AsyncTask<String, String, String> {

        private String resp;

        @Override
        protected String doInBackground(String... params) {
            InstanceID instanceID = InstanceID.getInstance(MainActivity.this);

            try {
                token = instanceID.getToken(
                        getString(R.string.gcm_defaultSenderId),
                        GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String result) {

            ((TextView) findViewById(R.id.text1)).setText(token);
        }

        @Override
        protected void onPreExecute() {

        }

    }
}
vishal jangid
  • 2,967
  • 16
  • 22