MainstreamDeveloper00 MainstreamDeveloper00 - 2 months ago 20
Android Question

How to fix Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE?

I encountered a strange problem - I've been using GCM in my application for quite a long time and everything works perfectly. However, before a release to Google Play I changed my application package name from
and after this GCM stopped working. At first I got en error
GCM sender id not set on constructor
and fixed it by overriding
getSenderIds(Context context)
, but now I can't get a registration ID. Here are the messages from logcat:
enter image description here

How can I fix this? When I switched to a new package I changed everything in the manifest file to the new package:

android:permission="" >
<action android:name="" />
<action android:name="" />
<category android:name="" />

So what is the problem behind this? Can renaming the application package cause this or is there another reason?


This SERVICE_NOT_AVAILABLE error says that GCM Service is not available in current. Wait and try after some time.

This happens many time (As my experience), so don't worry about it.

See the GCMConstants class of GCM Lib.

     * The device can't read the response, or there was a 500/503 from the
     * server that can be retried later. The application should use exponential
     * back off and retry.
    public static final String ERROR_SERVICE_NOT_AVAILABLE =

For more investigation see handleRegistration() of GCMBaseIntentService

private void handleRegistration(final Context context, Intent intent) {
        String registrationId = intent.getStringExtra(EXTRA_REGISTRATION_ID);
        String error = intent.getStringExtra(EXTRA_ERROR);
        String unregistered = intent.getStringExtra(EXTRA_UNREGISTERED);
        Log.d(TAG, "handleRegistration: registrationId = " + registrationId +
                ", error = " + error + ", unregistered = " + unregistered);

        // registration succeeded
        if (registrationId != null) {
            GCMRegistrar.setRegistrationId(context, registrationId);
            onRegistered(context, registrationId);

        // unregistration succeeded
        if (unregistered != null) {
            // Remember we are unregistered
            String oldRegistrationId =
            onUnregistered(context, oldRegistrationId);

        // last operation (registration or unregistration) returned an error;
        Log.d(TAG, "Registration error: " + error);
        // Registration failed
        if (ERROR_SERVICE_NOT_AVAILABLE.equals(error)) {
            boolean retry = onRecoverableError(context, error);
            if (retry) {
                int backoffTimeMs = GCMRegistrar.getBackoff(context);
                int nextAttempt = backoffTimeMs / 2 +
                Log.d(TAG, "Scheduling registration retry, backoff = " +
                        nextAttempt + " (" + backoffTimeMs + ")");
                Intent retryIntent =
                        new Intent(INTENT_FROM_GCM_LIBRARY_RETRY);
                retryIntent.putExtra(EXTRA_TOKEN, TOKEN);
                PendingIntent retryPendingIntent = PendingIntent
                        .getBroadcast(context, 0, retryIntent, 0);
                AlarmManager am = (AlarmManager)
                        SystemClock.elapsedRealtime() + nextAttempt,
                // Next retry should wait longer.
                if (backoffTimeMs < MAX_BACKOFF_MS) {
                  GCMRegistrar.setBackoff(context, backoffTimeMs * 2);
            } else {
                Log.d(TAG, "Not retrying failed operation");
        } else {
            // Unrecoverable error, notify app
            onError(context, error);