Search code examples
cloudmessagingservice-not-available

GoogleCloudMessaging.register - SERVICE_NOT_AVAILABLE error


Following is my code snippet

protected String doInBackground(Void... params) {
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS){
GoogleCloudMessaging gcm_instance = GoogleCloudMessaging.getInstance(context);
String reg_id = null;
int attempts = 0;
while(attempts < 3 && reg_id == null){
try{
    reg_id = gcm_instance.register(SENDER_ID);
    return reg_id;
} catch (IOException e) {           
    e.printStackTrace();
}
attempts++;
}
}
return null;
}

the register method is returning NULL and exception I am getting is SERVICE_NOT_AVAILABLE. I have cross checked the sender id and internet connection is working perfectly on my device.

Please help.


Solution

  • I had the same trouble. The solution was to use the helper libs as explained on this link: http://developer.android.com/google/gcm/helper.html#android-app

    For the record, the device I was using was running Android 4.0.3. I did setup a valid Google account on the device (eventually).

    Now I could register. Next step: seeing if I can actually push a message :D

    Good luck.