we using firebase cloud messaging in our app displaying push notifications. according firebaseinstanceid doc, instance id stable except when:
- app deletes instance id
- app restored on new device
- user uninstalls/reinstall app
- user clears app data
however every time launch app (previously stopped, not resumed), different token returned through firebaseinstanceidservice ontokenrefreshed() callback.
i wondering if normal behaviour of service or there bug in code.
update
dependency in root build gradle file:
classpath 'com.google.gms:google-services:3.0.0'
dependency in app build gradle file:
"com.google.firebase:firebase-messaging:9.2.1" "com.google.android.gms:play-services-base:9.2.1" // defined @ bottom of same file: plugin firebase apply plugin: 'com.google.gms.google-services'
firebaseinstanceidservice:
@override public void ontokenrefresh() { // saved token shared preferences final string oldtoken = prefshelper.getstringvalue(pref_device_token); log.d(tag, "old token: " + oldtoken); // updated instanceid token. final string refreshedtoken = firebaseinstanceid.getinstance().gettoken(); log.d(tag, "refreshed token: " + refreshedtoken); if (textutils.isempty(oldtoken)) { handlenewtoken(refreshedtoken); } else { handletokenupdate(oldtoken, refreshedtoken); } }
we using firebase cloud messaging in project too.
we use firebase in android app with:
compile 'com.google.firebase:firebase-core:9.0.2'
the token receipt persist whenever relaunch app.
it's better make sure if each time launch app, token refreshed in firebaseinstanceservice:
public class myfirebaseinstanceidservice extends firebaseinstanceidservice { private static final string tag = "myfirebaseiidservice"; @override public void ontokenrefresh() { ... // updated instanceid token. string refreshedtoken = firebaseinstanceid.getinstance().gettoken(); // check here. log.d(tag, "refreshed token: " + refreshedtoken); ... } }
then make sure in server have correctly set firebase server.
it bug if getting different token every time launching app. make sure have tested android project newest firebase library.
this questions related problem:
firebase android authentication failed: expired_token (auth token expired)
Comments
Post a Comment