FirebaseInstanceIdService is deprecated and OnNewToken() not working

I want to implement OnNewToken() method from FirebaseMessagingService in my Xamarin Android project that uses Firebase Cloud Messaging since FirebaseInstanceIdService and OnTokenRefreshed() are deprecated.

I tried this

[IntentFilter(new[] { "" })]
public class MessagingService : FirebaseMessagingService
    const string TAG = "MyFirebaseMsgService";
    public override void OnNewToken(string token)
        Log.Debug(TAG, "Refreshed token: " + token);

    public void SendRegistrationToServer(string token)


But my OnNewToken() is not hit. What am I doing wroing. Do i need to include anything in my Android manifest file? I cannot find any documents specific to Xamarin Android about this update. Please help. Thank you so much.


  • jezhjezh Member, Xamarin Team Xamurai

    The onNewToken method will only be called when a new token is generated.
    Quite often (especially during development) your app already have generated a token before you added the service. So onNewToken will not be called.
    If you want to get the token directly , the class FirebaseInstanceId may be helpful.

  • borge_rodsjoborge_rodsjo NOMember ✭✭

    @prabesh I have the same code as you, and I have the same problem; OnNewToken(string token) is not being called. I'm using all of the newest packages like:

    <package id="Xamarin.Firebase.Iid" version="70.1620.0-preview2" targetFramework="monoandroid90" />
    <package id="Xamarin.Firebase.Messaging" version="70.1710.0-preview2" targetFramework="monoandroid90" />
    <package id="Xamarin.Firebase.Config" version="70.1600.0-preview2" targetFramework="monoandroid90" />

    In my manifest I have this:

    <receiver android:exported="false" android:name=""/>
    <receiver android:exported="true" android:name="" 
            <action android:name=""/>
            <action android:name=""/>
            <category android:name="${applicationId}"/>

    Please, someone, look into the new way of getting FCM token

  • SagarPanwalaSagarPanwala USMember ✭✭✭

    I personally didn't try , but this can be useful.

    If you try , please let us know the feedback.

  • GautamJainGautamJain INMember ✭✭✭

    Fixed in latest Xamarin.Firebase.Messaging (still in preview) - Version 70.1710.0-preview2

  • DooksDooks ZAMember ✭✭✭

    It is now May 2019. Did you figure it out @prabesh

    I'm getting the following error:

    java.lang.NullPointerException: Attempt to invoke virtual method 'void' on a null object reference

    I have tried adding the following to the Manifest:

    <service android:name="" >
      <meta-data android:name="" android:value="" />
Sign In or Register to comment.