I'm trying to add Push Notifications to my Xamarin Forms app. Azure Notification Hub works fine, I see my server sent several messages. But they do not appear on my Android. I've implemented AzureNotificationHubService https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push#registering-with-the-azure-notification-hub, nor AndroidManifest or FirebaseRegistrationService.
But I wonder because RegisterAsync in AzureNotificationHubService is never called. Is that correct or am I missing something?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hmm, seems to be a problem of my emulator because on Hardware it works :-)
But nothing is displayed. Application output says:
[FirebaseNotificationService] Notification message body: Notification Hub test notification
[sfx] Unknown style!!! : com.android.internal.util.NotificationColorUtil@b5a3a2e
Downloaded demo app also has warnings on new Notification.Builder because SetSound is deprecated and Resource.Drawable.ic_stat_ic_notification is not found.
Any updates available?
Thanx for the feedback!
I have assigned this to the author to take a look if there are any issues with the steps in the document. Stay tuned :)
@K232 can you provide the link you used to download the demo app? Thanks!
Hi @conceptdev , it's from https://developer.xamarin.com/samples/xamarin-forms/WebServices/TodoAzurePush/ .
Thanks @K232, note that your emulator must be configured with Google Play Services (ie "a virtual device that has Google APIs set as the target"). The Play app should be present on the emulator - we'll make this more obvious in the doc.
We've identified this as a common cause of push notifications not working on emulators, since Google Play Services/Google APIs aren't automatically present in every emulator configuration (especially when it works fine on real hardware). You can read more about emulator configuration on the Xamarin site:
@K232 Before an Android app can receive push notifications, it must register with Firebase Cloud Messaging, which generates a registration token and returns it to the app. This is accomplished by:
FirebaseRegistrationService class does).When the app receives a registration token from Firebase, the FirebaseRegistrationService.OnTokenRefresh method is invoked, which in turn invokes SendRegistrationTokenToAzureNotificationHub, which in turn invokes AzureNotificationHubService.RegisterAsync.
The fact that AzureNotificationHubService.RegisterAsync is never called for you implies that the app isn't getting a token from Firebase, which implies either incorrect Firebase setup or the app not communicating with Firebase.
For more information about how to do this, see Sending Push Notifications from Azure Mobile Apps.
@K232 Also, I've fixed the deprecated SetSound API. However, I've no problems with Resource.Drawable.ic_stat_ic_notification. If it wasn't in the project, the app wouldn't build.
The doc and sample have been updated with the feedback from this conversation #please-close
Most helpful comment
@K232 Before an Android app can receive push notifications, it must register with Firebase Cloud Messaging, which generates a registration token and returns it to the app. This is accomplished by:
FirebaseRegistrationServiceclass does).When the app receives a registration token from Firebase, the
FirebaseRegistrationService.OnTokenRefreshmethod is invoked, which in turn invokesSendRegistrationTokenToAzureNotificationHub, which in turn invokesAzureNotificationHubService.RegisterAsync.The fact that
AzureNotificationHubService.RegisterAsyncis never called for you implies that the app isn't getting a token from Firebase, which implies either incorrect Firebase setup or the app not communicating with Firebase.For more information about how to do this, see Sending Push Notifications from Azure Mobile Apps.