Unable to create service de.appplant.cordova.plugin.background.ForegroundService: java.lang.SecurityException: Permission Denial: startForeground from pid=10397, uid=10226 requires android.permission.FOREGROUND_SERVICE ionic code example

Example: ionic foreground service

import { ForegroundService } from '@ionic-native/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();
}

Tags:

Misc Example