18

I use FCM in my project

It work correct on Sony xperia, Galaxy S6, Motorola and more. But on Galaxy S3 i get java.io.IOException: SERVICE_NOT_AVAILABLE error

Time of Galaxy S3 is auto and google play is updated

Internet connection is strong and i connected to open internet without proxy

AL.
  • 35,361
  • 10
  • 135
  • 270
Te Me
  • 205
  • 1
  • 3
  • 9
  • 3
    You may refer with this [thread](https://stackoverflow.com/questions/18325099/service-not-available-some-devices-on-android-gcm). This [error](https://developers.google.com/android/reference/com/google/android/gms/gcm/GoogleCloudMessaging#ERROR_SERVICE_NOT_AVAILABLE) means that your device can't read the response or there was a 500/503 from the server. You should use exponential back off and retry. – abielita May 07 '18 at 14:11
  • @abielita My app is crashing with `Fatal Exception: com.google.android.gms.tasks.RuntimeExecutionException java.io.IOException: SERVICE_NOT_AVAILABLE` while try to retrieve the token from result. so my concern is how to prevent the app from crashing with this error? – Stella Aug 08 '18 at 05:48
  • 1
    before accessing the result check for if(task!=null && task.isSuccessful())){ task.getResult()} this check will avoid app from getting crashed – Vijayalaxmi Dec 11 '20 at 18:38

4 Answers4

16

This error is caused when the device is unable to register to Firebase. Make sure the internet is working when this code is called. And put the code within try-catch to stop app from crashing.

Edit: Either add an internet connection check before registering the device or fetching token. Or wrap the Fetch token code in try-catch block to prevent app from crashing.

Insane Developer
  • 918
  • 7
  • 19
5

Check following:

1- Internet connection

2- Phone date/time to be correct

Hamed Jaliliani
  • 2,653
  • 22
  • 30
4

Make sure that you have included

task.isSuccessful()

check in your code inside overriden onComplete method like this -

FirebaseMessaging.getInstance().getToken() .addOnCompleteListener(new OnCompleteListener() {

        @Override
        public void onComplete(@NonNull Task<String> task) {
            if(task.isSuccessful()) {
                fcmToken = task.getResult();
            }
        }
    });

If not, whenever a network error or some other issue occurs at the time of registration of fcm token, then you may get FIS_Authentication_Failed or SERVICE_NOT_AVAILABLE type of errors.

Damanpreet Singh
  • 555
  • 8
  • 14
0

In my case problem was in Google Mobile Services app. After clearing its data problem disappeared.

I found a key for problem after launching on another device, where issue doesn't reproduces.

mohax
  • 4,235
  • 2
  • 35
  • 81