有问题的安装:
之前可以直接这样安装apk:
/** *@param file *@return *@Description 安装apk */
public void installApk(File file) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
但是在androud N上会报错,
android.os.FileUriExposedException
Android 7.0强制启用了被称作 StrictMode的策略,带来的影响就是你的App对外无法暴露file://类型的URI了。
如果你使用Intent携带这样的URI去打开外部App(比如:打开系统相机拍照),那么会抛出FileUriExposedException异常。
进入正题:开始解决异常
1、定义FileProvider
在Androidmanifest.xml文件中声明:
...
...
android:name="android.support.v4.content.FileProvider"
android:au