Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCM Messaging onTokenRefresh() is not called. #23

Closed
SagarGang opened this issue May 26, 2016 · 18 comments
Closed

FCM Messaging onTokenRefresh() is not called. #23

SagarGang opened this issue May 26, 2016 · 18 comments

Comments

@SagarGang
Copy link

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

@kroikie
Copy link
Contributor

kroikie commented May 26, 2016

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

@SagarGang
Copy link
Author

thanks for your reply.It work.

@sohel2178
Copy link

Thanks Kroikie Bro, Its Work

@zigic88
Copy link

zigic88 commented Oct 1, 2016

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.

@seunggabi
Copy link

@kroikie Thanks for your reply

@comm1x
Copy link

comm1x commented Dec 26, 2017

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

@thewijaysharma
Copy link

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

@kroikie
Copy link
Contributor

kroikie commented Mar 6, 2018

@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.

@sakshamsd
Copy link

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

@kroikie
Copy link
Contributor

kroikie commented Jun 27, 2018

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

@sakshamsd
Copy link

sakshamsd commented Jun 27, 2018 via email

@mob-rockstar
Copy link

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'

@kroikie
Copy link
Contributor

kroikie commented Aug 14, 2018

@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.

@ksurya28995
Copy link

ksurya28995 commented Dec 4, 2018

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 :(

@kroikie
Copy link
Contributor

kroikie commented Dec 4, 2018

@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.

@lgtout
Copy link

lgtout commented Mar 18, 2019

@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.

@leocarona
Copy link

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.

@sreejithvijayan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests