I'm trying to implement remote notifications in my Xamarin Android project. I followed step-by-step directions found in various guides but the OnTokenRefresh
method is never called, even the first time, so it looks like my app does not receive any kind of token or even does not make any type of firebase registration.
- I have added Firebase to my Android app and downloaded
google-services.json
- I included
google-services.json
in my Xamarin Android Project and set the Build Action to GoogleServicesJson I inserted this code in
AndroidManifest.xml
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" /> <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="${applicationId}" /> </intent-filter> </receiver>
I created a class that extends
FirebaseInstanceIdService
[Service] [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })] class FirebaseRegistrationService : FirebaseInstanceIdService { const string TAG = "FirebaseRegistrationService"; public override void OnTokenRefresh() { var refreshedToken = FirebaseInstanceId.Instance.Token; System.Diagnostics.Debug.WriteLine(TAG, "Refreshed token: " + refreshedToken); MainActivity.CurrentActivity.RunOnUiThread(() => RegisterDeviceOnServer(refreshedToken)); } public void RegisterDeviceOnServer(string refreshedToken) { // Custom implementation } }
As I have already said OnTokenRefresh
is never called.
What I can not understand is: who does the Firebase registration to receive a valid token?
Is there a missing directive?
Is there a missing method that makes this registration?
Why OnTokenRefresh
is never called?