exponea / exponea-flutter-sdk

MIT License
7 stars 9 forks source link

[ANDROID] empty gms token after update app #5

Closed ghost closed 2 years ago

ghost commented 2 years ago

Steps for debug: 1) do install old app without "Exponea" 2) do install new app includes "Exponea" 3) check logs.

You can see how "Exponea" send request with empty "Gms" token!

Steps for fixing this bug at now: 1) You need to check empty gms token in PreferenceManager.getDefaultSharedPreferences by "ExponeaFirebaseToken" key 2) If it empty, you need to call Firebase Messaging.getInstance().token and set to ExponeaPlugin.handleNewGmsToken

Temp solution private fun fixOrSkip() { try { val token = PreferenceManager.getDefaultSharedPreferences(context).getString( "ExponeaFirebaseToken", "" ) if (token.isNullOrBlank().not()) { return } FirebaseMessaging.getInstance().token.addOnSuccessListener { ExponeaPlugin.handleNewGmsToken(context, it) } } catch (e: Exception) { //do nothing } }

adam1929 commented 2 years ago

Thanks @ghost for your solution. You are right that Firebase token is not delivered to your app (and your app is not updating SDK) because app is "just" updated. Token generation is defined [here](https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceIdService.html#onTokenRefresh()) But your solution is fine, and I would approve it definitely! Because you may call 'FirebaseMessaging.getInstance().token' on every app start and you will get the same token every time (until it truly changed). I'm using this backup in every app personally :-) You created solution that is not asking for token if it is not needed, but please consider to 'not use hidden api', it may change anytime :-)