admin管理员组文章数量:1558092
在android10的环境下 发现部分华为手机不能正常更新安装,检查了一下爆出异常
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file://storage/emulated/0/文件夹名/文件名.apk typ=application/vnd.android.package-archive }
解决方法:
1.mainifest文件下添加:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="包名.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
2.xml文件:
<resources>
<paths>
<external-path path="." name="my_files" />
</paths>
</resources>
3.安装添加版本判断
private void installAPK() {
File apkFile = new File(saveFilePath);
if (!apkFile.exists()) {
return;
}
Intent i = new Intent(Intent.ACTION_VIEW);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { //10.0+以上版本
Uri apkUri = FileProvider.getUriForFile(context, "包名.fileProvider", apkFile); //与manifest中定义的provider中的authorities="包名.fileprovider"保持一致
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setDataAndType(apkUri, "application/vnd.android.package-archive");
} else {
i.setDataAndType(Uri.parse("file://" + apkFile.toString()),
"application/vnd.android.package-archive");
}
context.startActivity(i);
}
版权声明:本文标题:android10 部分机型(华为)无法正常更新安装app 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727319709a1108189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论