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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With