当前位置:   article > 正文

Using WebView from more than one process at once with the same data directory is not supported

using webview from more than one process at once with the same data director

错误日志:
Using WebView from more than one process at once with the same data directory is not supported

错误原因:
Android P行为变更,不可多进程使用同一个目录webView,需要为不同进程webView设置不同目录

解决办法:

Android 9 prohibit sharing WebView data directory among multiple processes
add below code in your mainApplication file

public void onCreate() {
        ...
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getProcessName(this);
            String packageName = this.getPackageName();
            if (!packageName.equals(processName)) {
                WebView.setDataDirectorySuffix(processName);
            }
        }
}

private String getProcessName(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
            if (processInfo.pid == android.os.Process.myPid()) {
                return processInfo.processName;
            }
        }
        return null;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

参考:
https://github.com/react-native-community/react-native-webview/issues/968

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/375312
推荐阅读
相关标签
  

闽ICP备14008679号