华为android6.0,代码安装apk,不会弹出安装界面
应用是这样,下载完成新版本apk后调用下面这段代码,弹出安装界面,让用户自己安装。但是在华为6.0(荣耀8)上只是闪一下,没有弹出安装界面。华为有什么拦截设置吗?
Intent i = new Intent(Intent.ACTION_VIEW);
i.setAction("android.intent.action.VIEW");
i.addCategory("android.intent.category.DEFAULT");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String type = getMIMEType(f);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
Uri uri=FileProvider.getUriForFile(context,"com.....app.fileprovider",f);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setDataAndType(uri,type);
}else{
i.setDataAndType(Uri.fromFile(f), type);
}
context.startActivity(i);
Build.VERSION.SDK_INT>=Build.VERSION_CODES.M
应该改为:
Build.VERSION.SDK_INT>=Build.VERSION_CODES.N
大意了,android6.0(M)还没有provider
试试这个
//安装apk
protected void installApk(File file) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intent, 0);// 如果用户取消安装的话,
// 会返回结果,回调方法onActivityResult
android.os.Process.killProcess(android.os.Process.myPid());
}
华为的系统需要声明权限
android.permission.REQUEST_INSTALL_PACKAGES