finally after 2 days i fixed above issue:
try below command.
$ ionic cordova platform rm android
$ ionic cordova platform rm ios
$ ionic cordova plugin add https://github.com/tushe/cordova-plugin-background-mode.git
$ npm install --save @ionic-native/background-mode
$ ionic cordova platform add android
$ ionic cordova platform add ios
If background-mode is not working set Below changes in the cordova-plugin-background-mode worked for me. Crash issue is resolved as well as background plugin is working fine.
In ForegroundService.java made below changes:
Add below import statement: import android.app.NotificationChannel;
b) Add below global variables:
public static final String NOTIFICATION_CHANNEL_ID_SERVICE = "de.appplant.cordova.plugin.background";
public static final String NOTIFICATION_CHANNEL_ID_INFO = "com.package.download_info";
c) Replace keepAwake() method with below code:
private void keepAwake() {
JSONObject settings = BackgroundMode.getSettings();
boolean isSilent = settings.optBoolean("silent", false);
if (!isSilent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.createNotificationChannel(new NotificationChannel(NOTIFICATION_CHANNEL_ID_SERVICE, "App Service", NotificationManager.IMPORTANCE_DEFAULT));
nm.createNotificationChannel(new NotificationChannel(NOTIFICATION_CHANNEL_ID_INFO, "Download Info", NotificationManager.IMPORTANCE_DEFAULT));
} else {
startForeground(NOTIFICATION_ID, makeNotification());
}
}
PowerManager powerMgr = (PowerManager)
getSystemService(POWER_SERVICE);
wakeLock = powerMgr.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "BackgroundMode");
wakeLock.acquire();
}
Add below in AndroidManifest.xml file:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
In code where I invoked background mode plugin, used disableWebViewOptimizations option on activate:
cordova.plugins.backgroundMode.on('activate', function() {
cordova.plugins.backgroundMode.disableWebViewOptimizations();
});
Above procedure worked for me.