How to fix Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE?
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 =
"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.resetBackoff(context);
GCMRegistrar.setRegistrationId(context, registrationId);
onRegistered(context, registrationId);
return;
}
// unregistration succeeded
if (unregistered != null) {
// Remember we are unregistered
GCMRegistrar.resetBackoff(context);
String oldRegistrationId =
GCMRegistrar.clearRegistrationId(context);
onUnregistered(context, oldRegistrationId);
return;
}
// 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 +
sRandom.nextInt(backoffTimeMs);
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)
context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + nextAttempt,
retryPendingIntent);
// 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);
}
}
Google Cloud Messaging Registration error: SERVICE_NOT_AVAILABLE? same project works fine on my laptop?
I found the issue Everything is ok but the problem is in my appcompact 7 library ,i removed it and now its work fine .
Android - GCM error 'SERVICE_NOT_AVAILABLE' on Android 6.0.1
Well, it turns out that my Google Play store wasn't working properly. I could view apps and install new ones but when I entered "My apps & games", it gave me the Check your connection and try again
error. So, I am posting this solution for anyone who might be having a similar problem since I spend 4-5 days looking for errors and trying different fixes.
Note: This is only for rooted users.
Steps:
- Open your FIle Manager. I used ES File Explorer.
- Goto "/" or the root of your phone
- There will be folder called
etc
- Inside
etc
, you'll see a file namehosts
- Inside the
hosts
file, you'll see 2 IP addresses. The second one will vary depending upon your location - Add a
#
at the start of the 2nd IP Address.#
will change that line to a comment
I recommend making a backup of the hosts file before editing.
Credits to "Ronny927": http://forum.xda-developers.com/showthread.php?t=2273994
Google Cloud Messaging - GCM - SERVICE_NOT_AVAILABLE
The problem was not code related, but link to the test phone.
The test phone do not have a SIM, and the clock was not set. So google cannot resgistred it with a wrong time.
I manage to have a registration Id using a Android Virtual Device, with google api, and by setting the test phone clock.
Related Topics
Calculate Elapsed Time in Java/Groovy
Custom JSON Deserialization with Jackson
Background Timer Task in Jsp/Servlet Web Application
Java.Sql.Sqlexception: No Suitable Driver Found for Jdbc:Microsoft:Sqlserver
Absolute Positioning Graphic JPAnel Inside Jframe Blocked by Blank Sections
How to Call Launch() More Than Once in Java
How Returns Xxxsize from Jcomponent(S) Added to the Jlabel
Jersey Rest Web Service with Activemq Middleware Integration
Math.Random, Only Generating a 0
Collections Sort(List<T>,Comparator<? Super T>) Method Example
Background Timer Task in Jsp/Servlet Web Application
Java: Why Do You Need to Specify an 'F' in a Float Literal