'How to create local notification in react native and android

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?



Solution 1:[1]

Yes, react-native-push-notifications. It does local notifications too on both iOS and Android.

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

Solution 2:[2]

Wix has the best plugin for notifications.

Includes Local Notifications AND Push (Android & iOS)

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

If you don't want to use push, you can skip the configuration and just install & link to start using

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

Take a look at the install guide: https://github.com/wix/react-native-notifications/blob/master/docs/installation.md

Example of use

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"
});

You can find more information on local notifications at https://wix.github.io/react-native-notifications/docs/localNotifications

Also, the notifications layout can be fully customized on Android

Solution 3:[3]

You can use https://github.com/zo0r/react-native-push-notification to handle local notification. You can use it with out GCM dependencies. Read through Usage section GCM and scheduled notifications are optional. I am using this with Jobscheduler to avoid FCM dependencies.

Solution 4:[4]

Consider Notifee library.

Notifee enables developers to rapidly build rich notifications with a simple API interface, whilst taking care of complex problems such as scheduling, background tasks, device API compatibility & more.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pomo
Solution 2 muZk
Solution 3 Ajitsen
Solution 4 Pavel Chuchuva