我正在尝试使用以下代码来安装保存在 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/