0

I have generated the android build but its not working in some Android version 9 devices in the android 9 version app is crashed after login.i got below error in the console.enter image description here

Tested In Following devices:

Oppo F11 Pro: app working not crashed.

Samsung, Nokia, MI: App crashed after login

Tried Below solution:

Add inside config.xml

1st Solution

<platform name="android">
    <config-file parent="./" target="app/src/main/AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    </config-file>
</platform>
2nd Solution : add in AndroidManifest.xml

> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"
> />

i tried each and everything but nothing worked for me can anybody help me?

Kapil Soni
  • 1,003
  • 2
  • 15
  • 37

2 Answers2

1

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.

Kapil Soni
  • 1,003
  • 2
  • 15
  • 37
0

If you are using Capacitor then you can use this

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>