Foreground Service
This plugin allows for android devices to continue running services in the background, using a foreground ongoing notification. This is targeted towards use with plugins such as 'cordova-geolocation' that will not run while the app is in the background on android API 26+.
For android API 28+, the following xml snippet should be inserted into config.xml
:
...
<platform name="android">
<config-file parent="/*" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
</config-file>
...
https://github.com/DavidBriglio/cordova-plugin-foreground-service
Stuck on a Cordova issue?
If you're building a serious project, you can't afford to spend hours troubleshooting. Ionicβs experts offer premium advisory services for both community plugins and premier plugins.
Installation
- Capacitor
- Cordova
- Enterprise
$ npm install cordova-plugin-foreground-service
$ npm install @awesome-cordova-plugins/foreground-service
$ ionic cap sync
$ ionic cordova plugin add cordova-plugin-foreground-service
$ npm install @awesome-cordova-plugins/foreground-service
Ionic Enterprise comes with fully supported and maintained plugins from the Ionic Team. Β Learn More or if you're interested in an enterprise version of this plugin Contact Us
Supported Platforms
- Android
Usage
React
Learn more about using Ionic Native components in React
Angular
import { ForegroundService } from '@awesome-cordova-plugins/foreground-service/ngx';
constructor(public foregroundService: ForegroundService) { }
...
startService() {
// Notification importance is optional, the default is 1 - Low (no sound or vibration)
this.foregroundService.start('GPS Running', 'Background Service', 'drawable/fsicon');
}
stopService() {
// Disable the foreground service
this.foregroundService.stop();
}