4

I have integrated Firebase Cloud Messaging + Azure Notification Hub into a Xamarin Android application.

Registering with Notification Hub is successful and I could able to view the registration id.

Below code shows how I register with notification hub.

public override void OnTokenRefresh()
    {
        var refreshedToken = FirebaseInstanceId.Instance.Token;
        Log.Debug(TAG, "FCM token: " + refreshedToken);
        SendRegistrationToServer(refreshedToken);
    }

async void SendRegistrationToServer(string token)
    {
        try
        {
            // Register with Notification Hubs
            hub = new NotificationHub(AndAppConsts.Hub_Name,
                                      AndAppConsts.DefaultListenSharedAccessSignature, MainActivity.instance);

            string[] tags = Settings.SubscriptionList.Split(';');

            await Task.Run(() =>
            {
                var regID = hub.Register(token, tags).RegistrationId;
                Log.Debug(TAG, $"Successful registration of ID {regID}");
            });
        }
        catch (Exception e)
        {
        }
    }

When I do a test send using Azure Notification Hub, I am getting below error for the registered Id.

The Push Notification System handle for the registration is no longer valid

I have given Firebase Server Key as the API key in Azure Access policy.

I would like to know why this error occurs.

Selvarathinam Vinoch
  • 1,080
  • 3
  • 13
  • 23
  • 1
    `The Push Notification System handle for the registration is no longer valid` means that your registration may be invalid. 1) Make sure the server key is correct 2) The registration needs to be re-register everytime your app start-up 3) You could follow [Diagnosis guidelines](https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-fixer) to troubleshoot this issue. – Bruce Chen Feb 22 '18 at 08:04
  • Moreover, you could follow [here](https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started) to check your configuration for azure notification hubs with FCM. – Bruce Chen Feb 22 '18 at 08:04
  • This could be also issue with Xamarin - when preserving data on device during deploy - token become invalid, but app wont get refreshed token! – Michal Dobrodenka Jul 02 '18 at 15:33

1 Answers1

0

I have found the root cause of the issue.

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

You must add above piece of code in Android Manifest.

GCM does not need this part since we give permission in code level but when we integrate FCM, we must give this in manifest.

Selvarathinam Vinoch
  • 1,080
  • 3
  • 13
  • 23
  • Android studio cannot find the FirebaseInstanceIdInternalReceiver. What jar should we include? – horatius May 16 '18 at 13:33
  • I already had this in, but I get this issue on and off, sometimes works sometimes doesn't. Especially when App is closed – cfl Jul 26 '19 at 06:49
  • same for me, sometimes it works and sometimes doesnt – RL89 Nov 25 '20 at 20:26