Te Me
Te Me

Reputation: 315

Android: FCM java.io.IOException: SERVICE_NOT_AVAILABLE error on some devices

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

Upvotes: 28

Views: 43477

Answers (8)

Harshil Menpara
Harshil Menpara

Reputation: 1

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

Upvotes: 0

Tahir
Tahir

Reputation: 1

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

Upvotes: 0

Sahil Mehta
Sahil Mehta

Reputation: 1

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();

Upvotes: 0

Insane Developer
Insane Developer

Reputation: 1102

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);
    

Upvotes: 23

user1875926
user1875926

Reputation: 131

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])

Upvotes: 1

mohax
mohax

Reputation: 4585

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.

Upvotes: 4

Damanpreet Singh
Damanpreet Singh

Reputation: 726

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.

Upvotes: 10

Hamed Jaliliani
Hamed Jaliliani

Reputation: 2929

Check following:

1- Internet connection

2- Phone date/time to be correct

Upvotes: 8

Related Questions