How to create local notification in react native and android

时间:2016-09-01 06:13:06

标签: android notifications react-native

I am trying to create a local notification in android using react-native. My application is completely local, so I don't want to use GCM or FCM. I saw this question

where it is done using java. Is there wrapper or a library in react native to achieve the same?

I also saw PushNotificationIOS API, will it work with android?

3 个答案:

答案 0 :(得分:3)

是的,react-native-push-notifications。它在iOS和Android上都会进行本地通知。

https://github.com/zo0r/react-native-push-notification

答案 1 :(得分:1)

您可以使用https://github.com/zo0r/react-native-push-notification处理本地通知。您可以在没有GCM依赖项的情况下使用它。通读 Usage 部分的GCM和计划的通知是可选的。我在Jobscheduler中使用它来避免FCM依赖性。

答案 2 :(得分:1)

Wix是最好的通知插件。

包括本地通知推送(Android和iOS)

https://github.com/wix/react-native-notifications

如果您不想使用推送,则可以跳过配置,只需安装并链接即可开始使用

npm install --save react-native-notifications
react-native link react-native-notifications

看看安装指南:https://github.com/wix/react-native-notifications/blob/master/docs/installation.md

使用示例

let localNotification = NotificationsIOS.localNotification({
    body: "Local notificiation!",
    title: "Local Notification Title",
    sound: "chime.aiff",
    silent: false,
    category: "SOME_CATEGORY",
    userInfo: { }
});

NotificationsAndroid.localNotification({
    title: "Local notification",
    body: "This notification was generated by the app!",
    extra: "data"
});

您可以在https://github.com/wix/react-native-notifications/blob/master/docs/localNotifications.md

上找到有关本地通知的更多信息。

此外,通知布局可以在Android上完全自定义