react-native-foreground-event-service
This library enables you to run a foreground service and schedule a job in given interval. In the library AlarmManager is used to schedule the jobs. So you may want to have a look at the Android AlarmManager documentation at this url; https://developer.android.com/reference/android/app/AlarmManager
Note: As you might know IOS does not have such property as Foreground service, so this library for only Android development.
Getting started
$ npm install react-native-foreground-event-service --save
Mostly automatic installation
$ react-native link react-native-foreground-event-service
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.ForegroundEventLib.RNForegroundEventServicePackage;
to the imports at the top of the file - Add
new RNForegroundEventServicePackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-foreground-event-service' project(':react-native-foreground-event-service').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-foreground-event-service/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-foreground-event-service')
Usage
; // Register the event; let eventListenerRef = ForegroundEventService; // Unregister the event; eventListenerRef; // Start the foreground service; ForegroundEventService; // Update notification info ForegroundEventService; // Stop the foreground service; ForegroundEventService;