0

I'm looking for a way to handle registrations when user reinstalls an app (Android).

I manage device registration from backend using the installation method. This is the scenario that results in problem for me.

  1. User start app and call backend to register the device for notifications. Backend is provided with the PNS-handle that is received from FCM.
  2. The device is registered in backend database and in Azure Notification Hub using the method CreateOrUpdateInstallationAsync(Installation)

The device is now ready to receive notifications and it works fine.

  1. User uninstalls the app.
  2. User installs the app again.
  3. The app calls backend and register the device for notifications again. However there will be a new PNS handle retrieved from FCM than in step 1.

In the Device table in the backend database there are now two lines for the same device. When notifications are being pushed to devices there are two notifications pushed to the same device.

I have read about that you can use canonical_ids available in Firebase Cloud Messaging. However I don't know how I can take advantage of that when I'm using Azure Notification Hub.

NotificationOutcome outcome = await Hub.SendGcmNativeNotificationAsync(notification, tag);     

The response is of type NotificationOutcome and in the response I can't see anything that can help me to see if the registration is valid or not.

enter image description here

When I post directly to FCM using https://fcm.googleapis.com/fcm/send I get a response like this which gives me a result that can be used to handle old registrations on the server side.

{
  "multicast_id": 4654657432518406292,
  "success": 1,
  "failure": 0,
  "canonical_ids": 1,
      "results": [
     {
       "registration_id": "APA91bHGMrMcVW6QNCgH62LiNIk4b1dd40Loz-aRkQUUKCUJz1HijWS2zIPJ5273dFy62u8hLEVZDBUbv-mU-WYRPF2xHMl2OUnDk73U_gSG9OcnewfQQKTkSupFfOTVG1Q0KDuWB-41",
  "message_id": "0:1490359752341398%624ba715f9fd7ecd"
}
  ]
}
Magnus Wallström
  • 1,469
  • 4
  • 15
  • 23

2 Answers2

0

Azure Notification Hub automatically takes care of updating registration with canonical_id returned by FCM. Other than updating registration, is there any reason you want to retrieve the canonical_id?

Thanks,

Sateesh

Sateesh
  • 376
  • 1
  • 4
  • No other reason than just keeping track of registrations. Must be something with my implementation because the registrations doesn't seem to get updated automatically in my hub. I'm creating the installations server side using method CreateOrUpdateInstallationAsync(Installation installation) – Magnus Wallström Mar 26 '17 at 15:36
0

Per my understanding, you could configure InstallationId as a unique identifier (e.g. TelephonyManager.getDeviceId()) for your Android client user when invoking your back-end to register the device for notifications using the installation model. You could refer to this issue for generating a unique Android device ID.

Community
  • 1
  • 1
Bruce Chen
  • 18,207
  • 2
  • 21
  • 35