I am developing android app using react-native. I want to create local push notification by clicking on button. how can I do this? which all the libraries I need to import? prasanna
-
1Possible duplicate of How to create local push notification using react-native-push-notificationHariks– Hariks2017-03-30 13:32:57 +00:00Commented Mar 30, 2017 at 13:32
-
Possible duplicate stackoverflow.com/questions/43041667/…Hariks– Hariks2017-03-30 13:33:19 +00:00Commented Mar 30, 2017 at 13:33
Add a comment
|
2 Answers
import PushNotification from 'react-native-push-notification';
scheduleNotfication() {
PushNotification.localNotificationSchedule({
message: "My Notification Message", // message
date: new Date(Date.now() + (60 * 1000)) // your required time
});
}
call the scheduleNotfication() method inside button
Comments
You can use react-native-fcm plugin for local notification and scheduled notification.
Code snippet
_onLocalNotification(){
if(Platform.OS === "android"){
FCM.presentLocalNotification({
id: "UNIQ_ID_STRING", // (optional for instant notification)
title: this.state.content, // as FCM payload
body: this.state.content, // as FCM payload (required)
sound: "default", // as FCM payload
priority: "high", // as FCM payload
click_action: "ACTION", // as FCM payload
badge: 10, // as FCM payload IOS only, set 0 to clear badges
number: 10, // Android only
ticker: "My Notification Ticker", // Android only
auto_cancel: true, // Android only (default true)
large_icon: "ic_launcher", // Android only
icon: "ic_launcher", // as FCM payload, you can relace this with custom icon you put in mipmap
big_text: "Show when notification is expanded", // Android only
sub_text: "This is a subText", // Android only
color: "red", // Android only
vibrate: 300, // Android only default: 300, no vibration if you pass null
tag: 'some_tag', // Android only
group: "group", // Android only
my_custom_data:'my_custom_field_value', // extra data you want to throw
lights: true, // Android only, LED blinking (default false)
show_in_foreground: true // notification when app is in foreground (local & remote)
});
}
else{
FCM.scheduleLocalNotification({
fire_date: new Date().getTime() + 1000, //RN's converter is used, accept epoch time and whatever that converter supports
id: '1111',
body: this.state.content,
repeat_interval: 'day',
count: 3,
show_in_foreground: true
})
}
}
_onScheduledNotification(){
FCM.scheduleLocalNotification({
fire_date: new Date().getTime() + 5000, //RN's converter is used, accept epoch time and whatever that converter supports
id: '1111',
body: this.state.content,
repeat_interval: 'day',
count: 3,
show_in_foreground: true
})
}
Please check and let me know if you face any issue.
Note - Solution provided in question's comment uses react-native-push-notification plugin.
2 Comments
Durgaprasad Budhwani
run command
npm install react-native-fcm react-native-link react-native-fcm