Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@thevsstech/react-native-foreground-service
Advanced tools
React native module to start foreground service on android
A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track. Foreground services must display a notification. Foreground services continue running even when the user isn't interacting with the app.
See the Android official documentation for details on the concept.
$ npm install @voximplant/react-native-foreground-service --save
React Native 0.60+
CLI autolink feature links the module while building the app.
AndroidManifest.xml
:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
AndroidManifest.xml
:
<service android:name="com.voximplant.foregroundservice.VIForegroundService" android:stopWithTask="true"> </service>
React Native <= 0.59
$ react-native link @voximplant/react-native-foreground-service
AndroidManifest.xml
:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
AndroidManifest.xml
:
<service android:name="com.voximplant.foregroundservice.VIForegroundService" android:stopWithTask="true"> </service>
android/app/src/main/java/[...]/MainActivity.java
import com.voximplant.foregroundservice.VIForegroundServicePackage;
to the imports at the top of the filenew VIForegroundServicePackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':@voximplant_react-native-foreground-service'
project(':@voximplant_react-native-foreground-service').projectDir = new File(rootProject.projectDir, '../node_modules/@voximplant/react-native-foreground-service/android')
android/app/build.gradle
:
implementation project(':@voximplant_react-native-foreground-service')
AndroidManifest.xml
:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
AndroidManifest.xml
:
<service android:name="com.voximplant.foregroundservice.VIForegroundService"> </service>
Demo application: react-native-foreground-service-demo
import VIForegroundService from '@voximplant/react-native-foreground-service';
Since the foreground service must display a notification, for Android 8+ it is required to create a notification channel first:
const channelConfig = {
id: 'channelId',
name: 'Channel name',
description: 'Channel description',
enableVibration: false
};
VIForegroundService.createNotificationChannel(channelConfig);
async startForegroundService() {
const notificationConfig = {
channelId: 'channelId',
id: 3456,
title: 'Title',
text: 'Some text',
icon: 'ic_icon'
};
try {
await VIForegroundService.startService(notificationConfig);
} catch (e) {
console.error(e);
}
}
VIForegroundService.stopService();
static async startService(notificationConfig)
Starts the foreground service and displays a notification with the defined configuration
static async stopService()
Stops the foreground service
static async createNotificationChannel(channelConfig)
Creates a notification channel for the foreground service. For Android 8+ the notification channel should be created before starting the foreground service
NotificationChannelConfig
Property name | Description | Required |
---|---|---|
id | Unique channel id | yes |
name | Notification channel name | yes |
description | Notification channel description | no |
importance | Notification channel importance. One of:
| no |
enableVibration | Sets whether notification posted to this channel should vibrate. False by default. | no |
NotificationConfig
Property name | Description | Required |
---|---|---|
channelId | Notification channel id to display the notification | yes (Android 8+ only) |
id | Unique notification id | yes |
title | Notification title | yes |
text | Notification text | yes |
icon | Icon name | yes |
priority | Priority of this notification. One of:
| no |
FAQs
React native module to start foreground service on android
The npm package @thevsstech/react-native-foreground-service receives a total of 0 weekly downloads. As such, @thevsstech/react-native-foreground-service popularity was classified as not popular.
We found that @thevsstech/react-native-foreground-service demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.