lixplor / android-Q-A

🐞 android related questions and answers
0 stars 0 forks source link

Android N(7.0) 安装apk报错, 提示包管理器发生错误 #78

Closed lixplor closed 7 years ago

lixplor commented 7 years ago

在Android 7.0中的安装apk方法提示包管理器发生错误

lixplor commented 7 years ago

参考 #76

7.0中在使用Uri时需要添加Uri的权限:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);  // 增加授权
}
intent.setDataAndType(convertUri(new File(APK_FILE_PATH)), "application/vnd.android.package-archive");  // convertUri用于转换7.0的File的Uri
context.startActivity(intent);