question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android Token never refreshed

See original GitHub issue

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin:

  • 2.3.0

Device Tested On:

  • Samsung Galaxy S5 SM-G900I (Android 6.0.1)
  • HUAWEI T1 7.0 (Android 4.4.2)

Version of VS:

  • Mac 7.4.3

Version of Xamarin:

  • Android 8.2.0.16

Versions of other things you are using:

  • Xamarin Forms 2.5.0.12223
  • Xamarin.GooglePlayServices.* 60.1142.0

Steps to reproduce the Behavior

Call FirebasePushNotificationManager.Initialize(this, true, true, false); Unable to produce any other behaviour on Android,

Expected Behavior

Token is refreshed on every app launch.

Actual Behavior

  • OnTokenRefresh is never called
  • CrossFirebasePushNotification.Current.Token is not null but never changes after first install, resulting in “NotRegistered” when trying to push to device using FCM API.

Code snippet

In application OnCreate() FirebasePushNotificationManager.Initialize(this, true, true, false);

After user login

    if (CrossFirebasePushNotification.Current.Token != null) {
        RefreshToken(CrossFirebasePushNotification.Current.Token);
    }

    CrossFirebasePushNotification.Current.OnTokenRefresh += (source, data) => {
        if (data != null) {
            RefreshToken(data.Token);
        }
    };

    CrossFirebasePushNotification.Current.OnNotificationReceived += (source, data) => {
        if (data != null) {
            ReceiveNotification(data.Data);
        }
    };

    CrossFirebasePushNotification.Current.OnNotificationOpened += (source, data) => {
        if (data != null) {
            OpenNotification(data.Data);
        }
    };

    CrossFirebasePushNotification.Current.RegisterForPushNotifications();

Screenshots

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jaspervanmegrootcommented, May 3, 2018

Try initialize with this:

      var options = new FirebaseOptions.Builder()
                   .SetApplicationId("Your application id")
                   .SetApiKey("your api key")
                   .SetDatabaseUrl("your database url")
                   .SetStorageBucket("your storagebucket")
                   .SetGcmSenderId("Your gcm").Build();
                this.firebaseApp = FirebaseApp.InitializeApp(this, options);

                FirebasePushNotificationManager.Initialize(this, true);
0reactions
jdluzencommented, Jul 8, 2018

Very nice library @rdelrosario! Many thanks.

@mea-licensing I’ve had a similar issue caused by a combination of issues. 1) I had to have the linker keep PNFirebaseMessagingService or else the service was linked out and I’d never get a new token. 2) I do not get a new token every time on startup, but somehow my token expired really quickly, so the existing one in CrossFirebasePushNotification.Current.Token was never refreshed, which is likely due to 1. I’m currently using a combination of manually using FirebaseInstanceId.Instance.GetToken... for the initial registration, and then this plugin for everything else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When should we refresh android device token?
There is no guarantee that your FCM token will be refreshed every hour (or even ever) though, as you seem to expect. Given...
Read more >
How We Do Automatic Token Refreshing using Android's ...
Preparing the token refresh job​​ Our job was simple: Get a new token against the existing one. Revoke the old token.
Read more >
Lock.Android: Refresh JSON Web Tokens
Android : Refresh JSON Web Tokens ... Keep in mind that Refresh Tokens never expire. To request a new token, use A uth0.Android...
Read more >
Never getting a refresh token
I am unable to get a refresh token from Google. Notice I am using offline and force. But the token I get back...
Read more >
Refresh token expiring (with offline.access scope) - Twitter API ...
This trouble seems to happen when I restart the android studio emulator. The string of the refresh token that I have never used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found