I'm attempting to send local notifications when the app is closed or in the background using the react-native-background-task module in an Android environment. I have no problems sending local notifications when the application is active, but the notifications will not show up when the app is running in the background.
I am monitoring the background task using:
$ adb logcat *:S ReactNative:V ReactNativeJS:V BackgroundTask:V
I get the message that the "Job is running", but no notifications pop up as they should. Here is a sample of my code.
import React, {Component} from "react";
import {AppRegistry, AsyncStorage} from 'react-native';
import PushNotification from 'react-native-push-notification';
import BackgroundTask from 'react-native-background-task'
BackgroundTask.define( async () => {
PushNotification.configure({
onNotification: function(notification) {
console.log('NOTIFICATION: ', notification);
},
popInitialNotification: true,
});
PushNotification.localNotification({
bigText: "My big text",
subText: "This is a subText",
message: "My Notification Message"
})
BackgroundTask.finish()
});
type Props = {};
export default class PushNotifications extends Component<Props>{
state = {
}
componentDidMount = () => {
BackgroundTask.schedule()
}
render() {
return null;
}
};
I have the same problem.
I receive a notification like this:
{foreground: false, finish: 茠, google.delivered_priority: "normal", google.sent_time: 1561651708077, google.ttl: 2419200, 鈥
body: "Oito para as seis"
finish: 茠 finish()
foreground: false
google.delivered_priority: "normal"
google.message_id: "0:1561651708079685%630155f3f9fd7ecd"
google.original_priority: "normal"
google.sent_time: 1561651708077
google.ttl: 2419200
id: "-1747385201"
title: "test"
url: "https://github.com/zo0r/react-native-push-notification/issues/1105"
userInteraction: false
then i call this
PushNotification.localNotification({
title,
message,
url: articleURL,
});
And nothing happens, only a old huawei device that i have shows the notification. Recent phones dont.
I have the same problem.
I receive a notification like this:
{foreground: false, finish: 茠, google.delivered_priority: "normal", google.sent_time: 1561651708077, google.ttl: 2419200, 鈥 body: "Oito para as seis" finish: 茠 finish() foreground: false google.delivered_priority: "normal" google.message_id: "0:1561651708079685%630155f3f9fd7ecd" google.original_priority: "normal" google.sent_time: 1561651708077 google.ttl: 2419200 id: "-1747385201" title: "test" url: "https://github.com/zo0r/react-native-push-notification/issues/1105" userInteraction: falsethen i call this
PushNotification.localNotification({ title, message, url: articleURL, });And nothing happens, only a old huawei device that i have shows the notification. Recent phones dont.
I was able to fix my code in order to receive notifications. I was missing in the android manifest these lines from the README. I think the documentation for this library should be more clean and more well explained. Anyway, it's a good framework and it works.
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="YOUR NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
No success for me, I added the lines still same. When app is cleared from the RAM, no notifications are received
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.