图片发自简书App
封面图还是要有的
之前使用Intent 安装APK文件,使用下面的代码可以直接调起安装界面。
public void installAPK(Context context, File apkFile){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(apkFile),"application/vnd.android.package-archive");
context.startActivity(intent);
}
最近把targetSdkVersion升级到了26才发现app在Android 8.0的手机上无法正常安装,一查才知道从Android N(也就是Android API 24)开始直接执行上面的代码会报android.os.FileUriExposedException异常,需要使用FileProvider来处理对Content URI读取的临时授权问题。直接上解决方案
首先,需要在AndroidManifest.xml文件中的标签中定义FileProvider
...
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantU