-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] onMessageReceived throwing NPE #286
Comments
I have very similar or even the same issue. NotificationHub.start(
this.application,
hubName,
connectionString
)
NotificationHub.clearTags()
NotificationHub.addTag(userId)
NotificationHub.setListener(notificationViewModel) Expection found in Firebase logs:
Mostly it's happening after 0.5-2 seconds after start of MainActifity. OS (determined from Firebaes): All supported Android versions, from 8 to 13 I don't know what's happening there, maybe it's some kind of race condition - library trying to upack notification before NotificationHub.start() was called? |
@Klewerro since this repo doesn't seem to be actively maintained we finally coded a workaround that might also work for you. It's definitely not the most clean and elegant solution though. Essentially you just need to override the library's message receiver, to do so: Create a new class that extends FirebaseMessagingService, you'll have to force the package name to be "package com.microsoft.windowsazure.messaging.notificationhubs" in order to be able to use some of the library's private package methods, it should look similar to this (you can find NotificationDisplayer in this repo's examples):
And add the following to your Android Manifest:
With this you should be able to stop getting the annoying NPE. |
What is the NotificationDisplayer? I cannot find it anywhere? |
You can find NotificationDisplayer here in the repo just modify it to meet your needs. To be able to call registerApplication you'll need to use "package com.microsoft.windowsazure.messaging.notificationhubs" as the package name for MyFirebaseReceiver |
Describe the bug
NPE exception is sometimes thrown when onMessageReceived is invoked. The error was captured a couple of times via Crashlytics so cannot provide the exact state of the device at the time but mostly sure app was in background (98% of captured cases) and got a push notification.
Exception or Stack Trace
To Reproduce
Steps to reproduce the behavior:
Configure and register with valid credentials + TAG(s)
Receive a push notification (most likely with app on the background / killed)
Code Snippet
During main activity onCreate method:
NotificationDisplayer just set the channels, etc to be able to show the notification.
And once the user is signed in the following is invoked:
NotificationHub.addTag("[TAG_HERE]")
Expected behavior
No exceptions are thrown and events are handled seamlessly.
Setup (please complete the following information):
Information Checklist
The text was updated successfully, but these errors were encountered: