本文共 1346 字,大约阅读时间需要 4 分钟。
一、问题
升级的过程中报错:failed to find configured root that contains "";主要原因是7.0的uri获取方式更加安全了。
二、解决方法
1、在mainfest.xml的application下加入:
2、在res下创建xml文件夹,文件夹下创建file_paths.xml,file_paths.xml文件内容:
在这里要注意:
<paths>这个元素内可以包含以下一个或多个,具体如下:
<files-path name="name" path="path" /> 物理路径相当于Context.getFilesDir() + /path/。<cache-path name="name" path="path" />
物理路径相当于Context.getCacheDir() + /path/。<external-path name="name" path="path" />
物理路径相当于Environment.getExternalStorageDirectory() + /path/。<external-files-path name="name" path="path" />
物理路径相当于**Context.getExternalFilesDir(String) **+ /path/。<external-cache-path name="name" path="path" />
物理路径相当于Context.getExternalCacheDir() + /path/。<root-path name="root-path" path="." />
物理路径相当于外部存储卡3、升级代码
Intent intent = new Intent(Intent.ACTION_VIEW);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(SysMaintenanceActivity.this, BuildConfig.APPLICATION_ID + ".fileProvider", file); intent.setDataAndType(contentUri, "application/vnd.android.package-archive");} else { intent.setDataAndType(Uri.parse("file://" + file.getAbsolutePath()), "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);}startActivity(intent);
转载地址:http://upxab.baihongyu.com/