filename:文件名
File file = new File(filename);
Uri uri;
if(Build.VERSION.SDK_INT < 23)
{
uri = Uri.fromFile(file);
}
else
{
//7.0 ,使用FileProvider始终报错:解析安装包出错,所以经过1天多的折腾,以及在某群里问各位大牛,最终以这样的方式
//解决。
//严格模式,防止Uri.parse 报异常
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
uri = Uri.parse("file://" + file.getAbsolutePath());
}
L.e(filename, uri);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
亲测有效!