android 7.0适配(总结)

file_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!--context.getFileDir() /data/data/包名/files-->
<files-path
name="files-path"
path="" />
<!--context.getCacheDir() /data/data/包名/cache-->
<cache-path
name="cache-path"
path="" />
<!--Environment.getExternalStorageDirectory() /storage/emulated/0 -->
<external-path
name="external-path"
path="" />
<!--context.getExternalFilesDirs() /storage/emulated/0/Android/data/包名/files-->
<external-files-path
name="external-files-path"
path="" />
<!--context.getExternalCacheDirs() /storage/emulated/0/Android/data/包名/cache-->
<external-cache-path
name="external-cache-path"
path="" />
</paths>

原:
Uri uri = Uri.fromFile(new File(filename));
Intent localIntent = new Intent(Intent.ACTION_VIEW);
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
localIntent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(localIntent);

修改后:

Intent localIntent = IntentUtils.getInstallAppIntent(new File(filename), true);

localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(localIntent);

public static Intent getInstallAppIntent(final File file, final boolean isNewTask) {
if (file == null) return null;
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data;
String type = "application/vnd.android.package-archive";
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
data = Uri.fromFile(file);
} else {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String authority = Utils.getApp().getPackageName() + ".utilcode.provider";
data = FileProvider.getUriForFile(Utils.getApp(), authority, file);
}
intent.setDataAndType(data, type);
return getIntent(intent, isNewTask);
}

7.0 WebView 部分机型打不开 (未尝试)

转:https://blog.csdn.net/u012347067/article/details/70829013
https 请求 webview 有 证书校验

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
if (error.getPrimaryError() == SslError.SSL_DATE_INVALID
|| error.getPrimaryError() == SslError.SSL_EXPIRED
|| error.getPrimaryError() == SslError.SSL_INVALID
|| error.getPrimaryError() == SslError.SSL_UNTRUSTED) {
handler.proceed();
} else {
handler.cancel();
}
super.onReceivedSslError(view, handler, error);
}
通过重写:
onReceivedSslError 过滤掉 部分错误
SSL_DATE_INVALID 证书的日期是无效的
SSL_EXPIRED 证书已经过期
SSL_INVALID 一个通用的错误发生
SSL_UNTRUSTED 不受信任的证书颁发机构


参考:https://blog.csdn.net/namehybin/article/details/78571964
posted @ 2019-07-25 10:41  寒夜美美  阅读(878)  评论(0编辑  收藏  举报