private voidautoInstallApk(File file){
Logger.d("开始安装");
Logger.d(file.getPath());
if(FileUtil.getExtension(file.getPath()).equals("apk")){
Logger.d("正在安装");
finalIntent install =newIntent();
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
install.setAction(Intent.ACTION_VIEW);
Uri uri =null;
if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
uri = FileProvider.getUriForFile(Core.getApplicationContext(),"com.nbhero.jiebo.fileprovider", file);//通过FileProvider创建一个content类型的Uri
}else{
uri = Uri.fromFile(file);
}
install.setDataAndType(uri,"application/vnd.android.package-archive");
Log.e("zlz", Environment.getExternalStorageDirectory().getPath() );
Core.getApplicationContext().startActivity(install);
}
}
创建 provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.nbhero.jiebo.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
添加 xml