29

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

3
  • 3
    You may refer with this thread. This error 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. Commented May 7, 2018 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? Commented Aug 8, 2018 at 5:48
  • 1
    before accessing the result check for if(task!=null && task.isSuccessful())){ task.getResult()} this check will avoid app from getting crashed Commented Dec 11, 2020 at 18:38

8 Answers 8

24

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.

Example:

  1. Adding the internet connection check code:

     private boolean isNetworkConnected() {
       ConnectivityManager cm = (ConnectivityManager) 
       getSystemService(Context.CONNECTIVITY_SERVICE);
    
       return cm.getActiveNetworkInfo() != null && 
       cm.getActiveNetworkInfo().isConnected();
    }
    
  2. Internet check and move ahead.

    if (isNetworkConnected())
       refreshToken(this);
    
Sign up to request clarification or add additional context in comments.

3 Comments

kindly provide a sample try-catch here... thank you
Also, in my case, the problem might be, when phone connected to Charles proxy.
I turned on the internet and it works. thanks a lot!
11

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.

Comments

8

Check following:

1- Internet connection

2- Phone date/time to be correct

4 Comments

2- Phone date/time to be correct Why, it can cause this problem?
Date and time was the issue, cheers.
In my case, the POST_NOTIFICATIONS permission was not granted. Could this be causing the issue for me?
if you using Android go to Settings , then connections then Data usage ,then Allowed networks for apps , then select google play services , then select mobile data or wi-fi ,
4

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.

2 Comments

This resolved it for me after taking the following steps: - Ensure the SHA1 of my android app on play store has been added to the list of unrestricted apps. - Ensured the google_oauth_client for the play store credentials is both used in the code and on the google-services.json file. - Ensured the SHA1 of my android app on play store has been added to firebase. - Then I cleared the cache and storage of google play services app on my pixel 6. - Uninstalled and installed the app from playstore and VOILA, the app was able to retrieve token.
It was google play store, i simply cleared all data of google playstore and it worked!!!, thanks a lot man
1

If someone is still facing an error, please try adding the getToken and other firebase messaging calls in useEffect and add messaging as its dependency.

Sometimes, the app is trying to invoke these methods before the messaging library is getting initialized, so try wrapping your code in useEffect with messaging as dependency.

import messaging from '@react-native-firebase/messaging';

React.useEffect(() => {
  // Get the token
  const token = await messaging().getToken();
  // other messaging operations
}, [messaging])

Comments

0

Try removing this code from void main() and putting it somewhere else; e.g., after the user is successfully logged in, or inside the init function on the first page:

await Firebase.initializeApp();
await _firebaseMessaging.requestPermission();
final fCMToken = await _firebaseMessaging.getToken();

Comments

0

If you are using a proxy to monitor network, Firebase will not share its token. It's a security feature by Google.

Comments

0

Check your mobile internet connection. This can often occur when the net is off.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.