织梦如何做移动网站,wordpress状态修改,河北省城乡建设厅网站首页,做网站 创业安卓7.0开始#xff0c;不再允许在App中把 file://Uri 暴露给其他App#xff0c;因此在代码中需要做下版本判断#xff0c;在7.0版本及以上需要使用 FileProvider 生成 content://Uri 来代替 file://Uri。同时安卓工程需要做以下调整#xff1a;
1、在 AndroidManifest.xml…安卓7.0开始不再允许在App中把 file://Uri 暴露给其他App因此在代码中需要做下版本判断在7.0版本及以上需要使用 FileProvider 生成 content://Uri 来代替 file://Uri。同时安卓工程需要做以下调整
1、在 AndroidManifest.xml 的 application 标签页下增加 provider 声明application......providerandroid:nameandroid.support.v4.content.FileProviderandroid:authoritiescom.smartphone.wifikey.fileProviderandroid:grantUriPermissionstrueandroid:exportedfalsemeta-dataandroid:nameandroid.support.FILE_PROVIDER_PATHSandroid:resourcexml/filepath //provider/application
以上内容需注意 android:authorites 必须填写为实际访问的 App 包名称。2、在 res 目录下创建 xml 文件夹新建 filepath.xml 并填写以下内容
?xml version1.0 encodingutf-8?
pathsexternal-path nameexternal_files path./
/paths3、代码中增加对7.0版本的判断与处理private void installApk(File apkFile) {Intent intent new Intent(Intent.ACTION_VIEW);//判断是否是Android N以及更高的版本if (Build.VERSION.SDK_INT Build.VERSION_CODES.N) {intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);Uri contentUri FileProvider.getUriForFile(mContext, com.smartphone.wifikey .fileProvider, apkFile);intent.setDataAndType(contentUri, application/vnd.android.package-archive);} else {intent.setDataAndType(Uri.fromFile(apkFile), application/vnd.android.package-archive);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);}startActivity(intent);}
以上代码必须注意getUriForFile 方法的第二个参数必须为”实际访问的App包名.fileProvider”。另外在测试时如果出现其他异常留心检查下应用权限。有问题给我邮件或者评论哦觉得对你有帮助就点赞吧~:-)