Hi,
I am trying to get a local notification on Android and I see the below error when I run the device:
D/ReactNativeNotifs: Native method invocation: postLocalNotification
E/unknown:ReactNative: Exception in native call
java.lang.NullPointerException: Attempt to invoke interface method 'int com.wix.reactnativenotifications.core.notification.IPushNotification.onPostRequest(java.lang.Integer)' on a null object reference
at com.wix.reactnativenotifications.RNNotificationsModule.postLocalNotification(RNNotificationsModule.java:102)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:751)
.
.
Any idea, what could have been wrong?
notificationservice.js:
/*
*/
import {NotificationsAndroid} from 'react-native-notifications';
const postNotification = () => {
let localNotification = NotificationsAndroid.localNotification({
body: "My first notification",
title: "test title",
});
};
module.exports = postNotification;
Same problem here
"react-native-notifications": "1.2.52",
edit:
I think I found the cause. In the lib's PushNotification.java, the verifyNotificationBundle check is looking for a google.message_id key that doesn't seem to exist in a local notification. If you change the method to always returns true, the local notification will work.
private static boolean verifyNotificationBundle(Bundle bundle) {
if (bundle.getString("google.message_id") != null) {
return true;
}
return false;
}
Not sure why we are checking for a google message ID for local notification, maybe @yogevbd can shed some light on this. Or did we missed a setup step?
Any news on this? I'm also experiencing it. Thanks!
I worked around it by passing in an empty string for the 'google.message_id' value when calling localNotification(). I didn't try running instead against https://github.com/wix/react-native-notifications/pull/71, but I would hope that would resolve the issue.
I worked around it by passing in an empty string for the 'google.message_id' value when calling localNotification(). I didn't try running instead against #71, but I would hope that would resolve the issue.
Great, thanks! Works for me!
NotificationsAndroid.localNotification({
"title": "Local notification",
"body": "This notification was generated by the app!",
"extra": "data",
"google.message_id": "" // <-- Adding this line fixed the problem
});
Add the google.message_id worked for me as well. 馃し鈥嶁檪
Has anyone tried iOS yet? Is this on iOS as well?
Most helpful comment
Great, thanks! Works for me!