gpt4 book ai didi

android - 以编程方式安装 apk 时出错 : "android.content.ActivityNotFoundException: Unable to find explicit activity class"

转载 作者:行者123 更新时间:2023-11-29 16:25:04 32 4
gpt4 key购买 nike

我正在尝试使用以下代码来安装保存在 SD 卡上的 apk 文件并出现以下异常:“android.content.ActivityNotFoundException:无法找到显式 Activity 类 {com.android.packageinstaller/.PackageInstallerActivity}”。代码中,file代表apk文件的SD卡路径。

Intent resultIntent = new Intent(android.content.Intent.ACTION_VIEW);
resultIntent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
resultIntent.setClassName("com.android.packageinstaller", ".PackageInstallerActivity");
startActivity(resultIntent);

我该如何管理?

最佳答案

您可能想阅读 this blog post关于如何使用 PackageInstaller 安装和删除包。

请注意,由于包安装程序已注册为处理 MIME 类型 application/vnd.android.package-archive,因此您不必明确指定 Intent 类名; Intent 解析器应该找到合适的开始。

此外,只有当用户启用了 INSTALL_NON_MARKET_APPS 时,操作才会成功。这与您遇到的故障直接相关,但请记住这一点,因为您也可能会遇到这种情况。

关于android - 以编程方式安装 apk 时出错 : "android.content.ActivityNotFoundException: Unable to find explicit activity class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4859786/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com