quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

FCM Messaging onTokenRefresh() is not called.

Open SagarGang opened this issue 10 years ago • 18 comments

it gives the token but it doesn't go to onTokenRefresh() which i need to trigger my sendRegistrationToServer().

SagarGang avatar May 26 '16 05:05 SagarGang

onTokenRefresh in FirebaseInstanceIdService is only called when a new token is generated. If your app was previously installed and generated a token then onTokenRefresh would not be called. Try uninstalling and reinstalling the app to force the generation of a new token, this would cause onTokenRefresh to be called.

Also be sure that your FirebaseInstanceIdService is properly defined in your AndroidManifest.xml

kroikie avatar May 26 '16 14:05 kroikie

thanks for your reply.It work.

SagarGang avatar May 26 '16 15:05 SagarGang

Thanks Kroikie Bro, Its Work

sohel2178 avatar Aug 28 '16 11:08 sohel2178

Sorry, for my bad english. My token doesn't go to onTokenRefresh() I'm already add that service into manifest and also unistalling that application. But onTokenRefresh() never trigger. How to solve this ? Please help me.

zigic88 avatar Oct 01 '16 20:10 zigic88

@kroikie Thanks for your reply

seunggabi avatar Nov 06 '16 11:11 seunggabi

The bug still exists. It's very strange I need to ask my users to reinstall app.

comm1x avatar Dec 26 '17 14:12 comm1x

Its really strange that this topic is closed but in my app onTokenRefresh() is not getting called even after the reinstallation

thewijaysharma avatar Mar 06 '18 18:03 thewijaysharma

@comm1x the recommendation of uninstall and reinstall is only for development, this is not a solution for an app that is already in the hands of users. You are able to call FirebaseInstanceId.getInstance().getToken(); at any time to get the current token.

@thewijaysharma please ensure that your FirebaseInstanceIdService is correctly defined in your manifest.

kroikie avatar Mar 06 '18 19:03 kroikie

what if users have already installed the app and in a new update we need to implement FCM??

sakshamsd avatar Jun 26 '18 10:06 sakshamsd

@sakshamsd in that case you would get the same callbacks as if the app had been initially installed.

kroikie avatar Jun 27 '18 15:06 kroikie

I tried implementing FCM on app updates but I can't get any token. What should be done??

On Wed, Jun 27, 2018, 9:17 PM Arthur Thompson [email protected] wrote:

@sakshamsd https://github.com/sakshamsd in that case you would get the same callbacks as if the app had been initially installed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-android/issues/23#issuecomment-400718414, or mute the thread https://github.com/notifications/unsubscribe-auth/AbhOV3TSf5ggk9Hp1zgCixJzx41kyOInks5uA6VygaJpZM4InNzK .

sakshamsd avatar Jun 27 '18 15:06 sakshamsd

I have uninstalled app and installed again, but onTokenRefresh is never called. I am using Firebase 11.4.2 in Android studio 3.1.4. classpath 'com.google.gms:google-services:3.3.0'

mob-rockstar avatar Aug 14 '18 02:08 mob-rockstar

@sakshamsd and @mob-rockstar could you try using the latest SDK 17.3.0 and also be sure that you are extending the FirebaseMessagingService and overriding onNewToken.

kroikie avatar Aug 14 '18 15:08 kroikie

Can someone give us a solution for this? onNewToken is not getting called or initialized. Thus not getting the token to test the notification service in Firebase console.

Using: action android:name="com.google.firebase.MESSAGING_EVENT" under intent-filter of a service.

in class: @Override public void onNewToken(String s) { super.onNewToken(s); Log.e("newToken", "newToken: " + s); sendRegistrationToServer(s); SharedPreferences pref = getApplicationContext().getSharedPreferences(FCMNotificationVariables.SHARED_PREF, MODE_PRIVATE); pref.edit().putString("regId", s).apply(); }

Log e -> "newToken" is not found in the logcat console, thus seems like onNewToken() is not even called/intialized :(

ksurya28995 avatar Dec 04 '18 02:12 ksurya28995

@ksurya28995 onNewToken is only called when a new token is created. Try uninstalling the app and reinstalling, this will force the generation of a new token and you should see the token in the log.

kroikie avatar Dec 04 '18 18:12 kroikie

@ksurya28995 I've had the same problem. What I've seen is that, after the app is installed, Google/FCM may issue a new token and you will NOT get a callback to FirebaseMessagingService#onNewToken executed. That leaves any notification-sending backend with the old token, which will fail when sending via FCM. To remedy this, whenever a new screen is displayed, I request a token using FirebaseInstanceId.getInstance().getToken(). If the token has changed, I update my notification-sending backend. It's not the ideal solution, as notifications send by my backend will be undeliverable until the user navigates to a new screen. But it's the best I could think of.

lgtout avatar Mar 18 '19 00:03 lgtout

Having same issue here. Service is registered on the AndroidManifest (as it should be), but onNewToken doesn't get called. I'll have to work around same way as @lgtout did.

leocarona avatar Mar 20 '20 17:03 leocarona

After two days of troubleshooting, finally i found out that the latest versions of the below nuget packages (or may be one of them) is causing this. I downgraded to the below versions and it started working.

Xamarin.Azure.NotificationHubs.Android -> v0.6.0
  Xamarin.Firebase.Messaging -> v71.1740.0
  Xamarin.GooglePlayServices.Base -> v71.1610.0

sreejithvijayan avatar Dec 01 '20 09:12 sreejithvijayan