Azure / Azure/azure-notificationhubs-android

[QUERY] Why are my Android devices (sometimes) coming back as unregistered?

Open
#225 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
33
Forks
65
PR merge metrics
No merged PRs in 30d

Description

**Query/Question**
This may not be the correct place to ask this question, but I'm trying to figure out an issue I'm having with Android devices using Azure Notification Hub in a Xamarin application.

In particular, I'm having an issue where my Android devices will suddenly stop receiving notifications. Sometimes this happens immediately upon app installation, and other times it can be several days after the app has been installed and they've previously been able to receive notifications.

If I take the installation id of an affected device and try to message that device using cURL it will tell me the device isn't registered. If I try to message that installation using the Azure Portal it will tell me that the message was successfully sent, but that there are no matching targets. It's as if the token has been changed or invalidated, but I wasn't aware of this change.

It has been my understanding that a token is generally only created or changed if an app is newly installed, uninstalled/reinstalled, the user clears their data, or if a phone is restored. None of these things are happening here. A user is able to receive notifications one day, and then unable to receive them the next after making no changes.

I have the FirebaseMessagingService set up in my code. I have the OnNewToken() method overriden. In this method I save the token received to the local device. After the app boots up it checks for this token and uses it to query our database to see if we have a record of this device. If we do not then we save off that device information and register the device with the Azure hub. This all seems to work as expected. I would think that if the token is being invalidated on the Firebase side that OnNewToken() would be called again and that process could start over. Is that not how it works? Do I need to explicitly check for token changes when the app boots outside of OnNewToken() being called to account for this situation?

Also, if I am correct that a devices token is being invalidated or expired for some reason, why is that? The documentation for FCM best practices in regard to tokens seems to suggest that I'd only have to worry about updating tokens every month or two to avoid stale tokens. My devices will stop receiving notifications sometimes in 24 hours or less.

**Setup (please complete the following information if applicable):**
- OS: Android 10 and Android 11
- IDE : Visual Studio
- Version: 0.6.0

Upon posting this question I did notice that my nuget package is woefully out of date, and maybe that has somethin to do with it, but I would still like an explanation for my issue if possible.

**Information Checklist**
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x] Query Added
- [X] Setup information Added

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the registration flow around FirebaseMessagingService.OnNewToken(), the stored token, and Azure Notification Hub registration; compare an affected installation with the cURL and Portal results. Done means identifying a reproducible cause or documenting the required token-check behavior for Android 10/11, but the issue names no source file or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, azure, firebase
Domain
cloud, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.