1、不支持Http明文传输
1.在xml目录下新建一个network_security_config.xml文件
2.文件内容(也可以针对单个域名做适配)
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true"/>
</network-security-config>
3.在AndroidManifest.xml中,application标签下添加属性:
android:networkSecurityConfig="@xml/network_security_config"
2、Apache Http客户端被弃用
1.在application 标签下添加:
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
3、webview 无法多进程共用数据
1.在Application类的onCreate方法中添加:
private void initWebview () {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String processName = getCurProcessName(this);
if (!"com.phone.launcher.android".equals(processName)) {
WebView.setDataDirectorySuffix(processName);
}
}
}
private String getCurProcessName(Context context) {
int pid = android.os.Process.myPid();
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> infos = mActivityManager.getRunningAppProcesses();
if (infos == null) {
return null;
}
for (ActivityManager.RunningAppProcessInfo appProcess : infos) {
if (appProcess.pid == pid) {
return appProcess.processName;
}
}
return null;
}
4、强制执行FLAG_ACTIVITY_NEW_TASK标志位
在非Activity环境中使用startActivity启动Activity,需要添加
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
网友评论