Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseInstanceIdService does not get called

I followed the examples on the internet and reviewed many questions here and on other websites

I built my application so it handles FCM Notifications, but I still cant find out why FirebaseInstanceIdService does not get called.

I declared it in AndroidManifest.xml

<service android:name=".InstanceService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"></action>
    </intent-filter>
</service>

<service android:name=".MessageService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"></action>
    </intent-filter>
</service>

My Service is

public class InstanceService extends FirebaseInstanceIdService {
    private static final String REG_Token="REG_Token";

    @Override
    public void onTokenRefresh() {

        String recent_token= FirebaseInstanceId.getInstance().getToken(); // get token from the server

        Log.d(REG_Token,recent_token); // show device token in Logcat View

    }

I look at Logcat but there is no REG_Token there.

I tried to debug the code and stopped it at Log.d(REG_Token,recent_token);, but it did not stop there.

I think the service is not called at all and I can't find out why.

like image 424
asmgx Avatar asked Jan 04 '23 20:01

asmgx


1 Answers

From this documentation

The registration token may change when:

  • The app deletes Instance ID
  • The app is restored on a new device
  • The user uninstalls/reinstall the app
  • The user clears app data.

It means that the onTokenRefresh() method is not called every time the app is opened but only when one of those 4 events occurred.

The simplest way is to uninstall the app and then install the app again. After it's installed, open the app and then look at the logcat (based on your code).

Hope this helps :)

like image 195
Wilik Avatar answered Jan 13 '23 13:01

Wilik