I have an Android app with firebase notification services currently on deployment.
The google-services.json file associated with it had wrong entries.
I fixed the .json file and firebase services are now working as usual for newly installed apps.
But for current users it is not working (Because it is still using the old token).
Called when the system determines that the tokens need to be refreshed. The application should call getToken() and send the tokens to all application servers.
This will not be called very frequently, it is needed for key rotation and to handle Instance ID changes due to:
App deletes Instance ID
App is restored on a new device
User uninstalls/reinstall the app
User clears app data
The system will throttle the refresh event across all devices to avoid overloading application servers with token updates.
I tried deleting the instanceId programmatically (So I get a new token); it gets deleted (no exception is thrown) but then the new token is the same as the old one.
Shouldn't changing the google-services.json trigger a token change automatically?
How can I solve this without re-installing the app for current users (on update)?
I am using the latest versions of Firebase and google-services (in Gradle).
You can update your app by submitting the new apk to the play store. So after old customers update your apk old customers will be replaced by new apk and new google-services.json file. Make sure your code is written to call the onRefreshToken() method and get the new token and send it to your server for further communication. When this is updated. All your new customers will be able to receive the notifications.
#Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.d("NEW_TOKEN",s);
}
Related
I am getting an error when I try to send messages via the Firebase Notification screen in the console. It says I have an invalid token format, but I have used previously used tokens collected with the same method successfully.
I was not getting this error a few days ago, and notifications were working properly. I just pushed an update to the Google Play Store recently, but this update did not touch any code relating to the notifications.
status.firebase.google.com says that notifications are currently up. All other Firebase usages in my app (database, storage, auth) are working properly.
When I updated my app, I did not change my google-services.json file at all. Do I need to do some sort of update to this file, or some sort of version change on the Firebase Console to keep the versions consistent between the APK and the console?
As mentioned by #Arthur Thomson (in the comments), your registration token may change as a result of an update in the application. It does matter that you did not change the google-services.json if the user reinstalled or updated the application the token maybe changed.
According to the docummentation about the device registration token, the registration toke 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.
So you would need to retrieve the new registration token using the onTokenRefresh() method in your Android client application. I mean, you just need to implement a code to retrieve the new token if it changes.
Hope this helps
I have implemented FCM in version 6 of my Android application. onTokenRefresh() is getting called if my app is not previously installed. But when my app with a previous version (which did not have FCM implemeted) is already installed and I update it with version 6, then the onTokenRefresh() is not getting called.
Do I need to uninstall the previous app version from Play Store and then install new version?
I think that should still be the intended behavior. onTokenRefresh() will be called the first time the app is installed. Not every time it's updated. So maybe, you could manually force the onTokenRefresh() like what is mentioned in this post:
If you would like to manually force the onTokenRefresh(), you can create an IntentService and delete the token instance. Then, when you call getToken, the onTokenRefresh() method will be called again.
I would like to know what the default authentication period for users to be logged into Firebase is. I have an Android app where users are logging in via email/password and I want to know how long FirebaseAuth.getInstance().getCurrentUser() will remain not null.
In the previous version of Firebase, the default length of time was 24 hours and could be modified via the firebase console. Is the default amount of time still 24 hours? Can this be modified via the console? (I cannot seem to find anything regarding this in the latest version of Firebase)
I realize this question is six years old at this point, but as mentioned in the comments, the user lifecycle states that the user token will expire and that in that event, the refresh token will be used to automatically reissue a set of new tokens for the user when using the SDKs. This allows the user to continue using the app without issue and does not force the user to re-authenticate into the app when their session token has expired.
I was under the impression that the GCM registration is always the same for the same combination of device, application and application version.
But now I realized that it always changes when I uninstall the application and then install it again.
The Problem
My app create a profile for each device the user uses. So if a user install the app, uninstall it and install it again, the app will have two profiles for the same user in the same device.
I am currently storing the registration id in the shared preferences to update the profile if the registration id changes, but when the app is uninstalled the shared preferences are lost.
The Question
Is there anyway to preserve the registration id after the app is uninstalled?
Any other idea of how can I update one of the existing profiles (identified by the old registration id) instead of creating a new one?
You can use Google Backup Services to preserve data of application even after uninstall
Ref: http://developer.android.com/guide/topics/data/backup.html#BackupKey
OnBackup() // can save GCMId
OnRestore() // can retrive the same
From the GCM docs:
When an application is updated, it should invalidate its existing
registration ID, as it is not guaranteed to work with the new version.
Because there is no lifecycle method called when the application is
updated, the best way to achieve this validation is by storing the
current application version when a registration ID is stored. Then
when the application is started, compare the stored value with the
current application version. If they do not match, invalidate the
stored data and start the registration process again.
When the docs state that "it is not guaranteed to work with the new version" is that a GCM limitation or are they speculating about potential changes in my app's behavior from version to version?
From the app side I can more-or-less guarantee that successive versions will function properly with respect to GCM and whatever app-specific message format I concoct. Do I still need to re-register?
If so, which should I use to detect a "new version": version code or version name? My understanding is that these are "free form" and the app developer sets them to whatever values he chooses. So, what if I put an app update in the store but don't change versionName or versionCode; would I need to re-register with GCM?
It seems like what GCM actually wants is for the app to re-register each time a new installation is launched for the first time (and each time it's successively launched until registration is complete), regardless of the values in versionName and versionCode. Is that an accurate statement?
I don't remember where we've read it, but it came to our attention that when a device gets a push while an app is not installed, Google will invalidate the registration id.
This makes sense if the app is really uninstalled, but if the device was actually in the middle on an update, it quickly uninstalls and re-installs, so google might mistakenly think the registration needs to be invalidated.
The solution seems like to re-register on the first launch after an update, to guarantee your app registration id is active.
Version code is indeed a freely selected number, but you must increase it on every new version you publish to google play, so you can check if that number has changed, and know your app had been updated and you need to refresh the registration.
EDIT:
This is also relevant to C2DM's successor GCM, with a lot more docs explaining this behavior and how to properly write code.
See: http://developer.android.com/google/gcm/client.html with all the details.
Specifically this code, where getRegistrationId will return an empty string in case the version code changed forcing the client to register again:
if (checkPlayServices()) {
gcm = GoogleCloudMessaging.getInstance(this);
regid = getRegistrationId(context);
if (regid.isEmpty()) {
registerInBackground();
}
} else {
Log.i(TAG, "No valid Google Play Services APK found.");
}
I would use the Version Code to detect the app update. The Version Code is forced to change every time you submit a new version to the Google Play store, hence you can rely on it to detect the app's version.