Ionic3致命异常:android.app.RemoteServiceException:android 9设备中的startForeground错误通知?

问题描述 投票:0回答:1

我已生成android内部版本,但登录后我的android 9版本应用中的某些Android版本9设备无法正常工作。控制台中出现以下错误。enter image description here

在以下设备中测试:

Oppo F11 Pro:应用程序未崩溃。

[三星,诺基亚,密歇根州:应用程序在登录后崩溃

尝试以下解决方案

在config.xml中添加

第一解决方案

<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"
> />

我尽了一切,但对我没有任何帮助的人可以帮助我吗?

ionic3 android-9.0-pie background-mode
1个回答
0
投票

最后两天后,我修复了上述问题:

尝试以下命令。

$ 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

如果没有设置背景模式,则下面的cordova-plugin-background-mode更改对我有用。崩溃问题已解决,并且后台插件运行正常。

在ForegroundService.java中进行了以下更改:

Add below import statement: import android.app.NotificationChannel;

b)添加以下全局变量:

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)用下面的代码替换keepAwake()方法:

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();
}

在AndroidManifest.xml文件中添加以下内容:

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

在我调用了后台模式插件的代码中,在激活时使用了disableWebViewOptimizations选项:

cordova.plugins.backgroundMode.on('activate', function() {
       cordova.plugins.backgroundMode.disableWebViewOptimizations();
 }); 

上面的过程对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.