{"id":13577514,"url":"https://github.com/voximplant/react-native-foreground-service","last_synced_at":"2025-04-09T08:07:19.007Z","repository":{"id":34067495,"uuid":"166025120","full_name":"voximplant/react-native-foreground-service","owner":"voximplant","description":"React native module to start foreground service on android","archived":false,"fork":false,"pushed_at":"2024-07-11T19:49:24.000Z","size":26,"stargazers_count":160,"open_issues_count":47,"forks_count":91,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-02T06:48:07.547Z","etag":null,"topics":["android","react","voximplant"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voximplant.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-16T10:59:13.000Z","updated_at":"2025-02-23T15:21:41.000Z","dependencies_parsed_at":"2024-01-16T20:28:57.154Z","dependency_job_id":"bda7e420-ec78-4254-bd83-e619c87564a8","html_url":"https://github.com/voximplant/react-native-foreground-service","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":"0.33333333333333337","last_synced_commit":"9bfe049627b399ac939d6824129fb688a2a73a95"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voximplant%2Freact-native-foreground-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voximplant%2Freact-native-foreground-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voximplant%2Freact-native-foreground-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voximplant%2Freact-native-foreground-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voximplant","download_url":"https://codeload.github.com/voximplant/react-native-foreground-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247615417,"owners_count":20967183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","react","voximplant"],"created_at":"2024-08-01T15:01:22.103Z","updated_at":"2025-04-09T08:07:18.990Z","avatar_url":"https://github.com/voximplant.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"\n# react-native-foreground-service\n\nA foreground service performs some operation that is noticeable to the user. \nFor example, an audio app would use a foreground service to play an audio track. \nForeground services must display a notification. \nForeground services continue running even when the user isn't interacting with the app.\n\nSee [the Android official documentation](https://developer.android.com/guide/components/services) for details on the concept.\n\n\n## Getting started \n\n`$ npm install @voximplant/react-native-foreground-service --save`\n\n### Automatic installation (Android only)\n\n- React Native 0.60+\n\n    CLI autolink feature links the module while building the app.\n\n    1. Add the FOREGROUND_SERVICE permission to the application's `AndroidManifest.xml`:\n        ```\n        \u003cuses-permission android:name=\"android.permission.FOREGROUND_SERVICE\"/\u003e\n        ```\n    2. Add VIForegroundService as a service to the application's `AndroidManifest.xml`:\n        ```\n        \u003cservice android:name=\"com.voximplant.foregroundservice.VIForegroundService\"\u003e \u003c/service\u003e\n\n- React Native \u003c= 0.59\n\n    `$ react-native link @voximplant/react-native-foreground-service`\n\n    1. Add the FOREGROUND_SERVICE permission to the application's `AndroidManifest.xml`:\n        ```\n        \u003cuses-permission android:name=\"android.permission.FOREGROUND_SERVICE\"/\u003e\n        ```\n    2. Add VIForegroundService as a service to the application's `AndroidManifest.xml`:\n        ```\n        \u003cservice android:name=\"com.voximplant.foregroundservice.VIForegroundService\"\u003e \u003c/service\u003e\n        ```\n\n### Manual installation (Android only, React Native \u003c= 0.59)\n1. Open up `android/app/src/main/java/[...]/MainActivity.java`\n    - Add `import com.voximplant.foregroundservice.VIForegroundServicePackage;` to the imports at the top of the file\n    - Add `new VIForegroundServicePackage()` to the list returned by the `getPackages()` method\n2. Append the following lines to `android/settings.gradle`:\n  \t```\n  \tinclude ':@voximplant_react-native-foreground-service'\n    project(':@voximplant_react-native-foreground-service').projectDir = new File(rootProject.projectDir, '../node_modules/@voximplant/react-native-foreground-service/android')\n  \t```\n3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:\n  \t```\n    implementation project(':@voximplant_react-native-foreground-service')\n  \t```\n4. Add the FOREGROUND_SERVICE permission to the application's `AndroidManifest.xml`:\n    ```\n    \u003cuses-permission android:name=\"android.permission.FOREGROUND_SERVICE\"/\u003e\n    ```\n5. Add VIForegroundService as a service to the application's `AndroidManifest.xml`:\n    ```\n    \u003cservice android:name=\"com.voximplant.foregroundservice.VIForegroundService\"\n             android:exported=\"false\"\u003e \u003c/service\u003e\n    ```\n6. For targetSdkVersion Android API \u003e= 31\n\n    Add android:exported=\"true\" to the application's `AndroidManifest.xml` activity section\n    ```\n    \u003cactivity\n        android:name=\".MainActivity\"\n        android:label=\"@string/app_name\"\n        android:configChanges=\"keyboard|keyboardHidden|orientation|screenSize\"\n        android:windowSoftInputMode=\"adjustResize\"\n        android:exported=\"true\"\u003e        \u003c===== Add this line\n    ```\n\n## Demo project\nDemo application: [react-native-foreground-service-demo](https://github.com/voximplant/react-native-foreground-service-demo)\n  \t\n## Usage\n\n### Import module\n```javascript\nimport VIForegroundService from '@voximplant/react-native-foreground-service';\n```\n\n### Create notification channel (Android 8+)\nSince the foreground service must display a notification, for Android 8+ it is required to create a notification \nchannel first:\n```javascript\nconst channelConfig = {\n    id: 'channelId',\n    name: 'Channel name',\n    description: 'Channel description',\n    enableVibration: false\n};\nawait VIForegroundService.getInstance().createNotificationChannel(channelConfig);\n```\n\n### Start foreground service\n```javascript\nasync startForegroundService() {\n    const notificationConfig = {\n        channelId: 'channelId',\n        id: 3456,\n        title: 'Title',\n        text: 'Some text',\n        icon: 'ic_icon',\n        button: 'Some text',\n    };\n    try {\n        await VIForegroundService.getInstance().startService(notificationConfig);\n    } catch (e) {\n        console.error(e);\n    }\n}\n```\n\n### Stop foreground service\n```javascript\nawait VIForegroundService.getInstance().stopService();\n```\n\n## Reference\n\n### Methods\n```javascript\nasync startService(notificationConfig)\n```\nStarts the foreground service and displays a notification with the defined configuration\n\n------------------------------\n\n```javascript\nasync stopService()\n```\nStops the foreground service\n\n------------------------------\n\n```javascript\nasync createNotificationChannel(channelConfig)\n```\nCreates a notification channel for the foreground service. \nFor Android 8+ the notification channel should be created before starting the foreground service\n\n------------------------------\n\n```javascript\non(event, handler)\n```\nAdds a `handler` to be invoked when a button on the notification is pressed.\nSupported event: `VIForegroundServiceButtonPressed`.\n\n------------------------------\n\n```javascript\noff(event, handler)\n```\nRemoves the registered `handler` for the `VIForegroundServiceButtonPressed` event.\nIf `handler` is not provided, this function will remove all registered handlers.\n\n### Configs\n```javascript\nNotificationChannelConfig\n```\n| Property name   | Description                                                                                                           | Required |\n|-----------------|-----------------------------------------------------------------------------------------------------------------------|----------|\n| id              | Unique channel id                                                                                                     | yes      |\n| name            | Notification channel name                                                                                             | yes      |\n| description     | Notification channel description                                                                                      | no       |\n| importance      | Notification channel importance. One of:\u003cul\u003e\u003cli\u003e1 – 'min'\u003c/li\u003e \u003cli\u003e2 – 'low' (by default)\u003c/li\u003e\u003cli\u003e3 – 'default'\u003c/li\u003e\u003cli\u003e4 – 'high'\u003c/li\u003e\u003cli\u003e5 – 'max'\u003c/li\u003e\u003c/ul\u003e | no       |\n| enableVibration | Sets whether notification posted to this channel should vibrate. False by default.                                    | no       |\n\n```javascript\nNotificationConfig\n```\n\n| Property name | Description                                                                                                                                             | Required              |\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|\n| channelId     | Notification channel id to display the notification                                                                                                     | yes (Android 8+ only) |\n| id            | Unique notification id                                                                                                                                  | yes                   |\n| title         | Notification title                                                                                                                                      | yes                   |\n| text          | Notification text                                                                                                                                       | yes                   |\n| icon          | Icon name                                                                                                                                               | yes                   |\n| button        | Button text                                                                                                                                             | no                    |\n| priority      | Priority of this notification. One of: \u003cul\u003e\u003cli\u003e\u0026nbsp;0 – PRIORITY_DEFAULT (by default)\u003c/li\u003e\u003cli\u003e-1 – PRIORITY_LOW\u003c/li\u003e\u003cli\u003e-2 – PRIORITY_MIN\u003c/li\u003e\u003cli\u003e\u0026nbsp;1 – PRIORITY_HIGH\u003c/li\u003e\u003cli\u003e\u0026nbsp;2 – PRIORITY_MAX\u003c/li\u003e\u003c/ul\u003e | no       |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoximplant%2Freact-native-foreground-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoximplant%2Freact-native-foreground-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoximplant%2Freact-native-foreground-service/lists"}