Using the Azure Notification Hub Android SDK, I have tried to remove tags associated with my user in Android, but I am unable to do so. I have tried removing them two different ways:
- First add a tag, then restart the app without
NotificationHub.addTag("myTag"), but instead includeNotificationHub.removeTag("myTag"). Result:.addTagwill return with false, indicating that no tag was removed. - Add a tag and remove it in the next line. Result:
.removeTagreturns true, indicating the tag is removed.
The problem: The Notification Hub on Azure still sends messages to this user with the tag "myTag", no matter which way I remove the tag.
Full code:
NotificationHub.start(application, hubName, connectionString)
NotificationHub.setListener(AzureNotificationListener())
NotificationHub.addTag("myTag")
NotificationHub.remove("myTag")
- OS: Android 12
- IDE : Android Studio Giraffe 2022.3.1 Patch 1
- Library: "com.microsoft.azure:notification-hubs-android-sdk-fcm:2.0.0"
All that is required is calling the
NotificationHub.removeTag("myTag")method. The SDK will take care of the rest.It may be there's another reason the device is always being targeted. I would check for other Installations that target the same device handle, and have the tag you're looking for. There is also some latency between when you remove the tag and when ANH's records reflect the change. If nothing else, the SDK waits a few seconds between when the method is called and when it creates an HTTP request to update the backend. If you're too trigger happy, you may be losing a race.