Created
February 10, 2023 01:12
-
-
Save thoinv/b6dfaf8c79a30a2e915c89e4b26ebb4c to your computer and use it in GitHub Desktop.
[WebView multi process error Solution] Android 9 prohibit sharing WebView data directory among multiple processes add below code in your main #webview #solution #android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment