android - 尝试从其他应用安装 APK 时如何使用默认包安装程序(Android)?

标签 android android-intent installation apk android-package-managers

我一直在尝试从我的应用程序安装其他应用程序。我已经从服务器下载了 .apk,并且正在使用以下内容触发 intent

Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);

installIntent.setData(Uri.parse("file:<apk file location>"));
installIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, DOWNLOADED_PACKAGE_NAME);
installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);

startActivityForResult(installIntent, REQUEST_INSTALL); 
  • 但我在尝试安装软件包时一直坚持设置默认安装程序。
  • 一旦我的安装 Intent 被触发,就会显示以下提示,要求用户选择一个默认应用程序来处理不需要的 Intent 。
  • 不应向用户显示此提示。
  • 所需的行为是像 Google Play 一样在下载完成后开始安装包。
  • 点击安装按钮 --> 下载 --> 请求许可 --> 安装。

如何避免这个提示?

此功能仅从 4.2 开始添加。

enter image description here

最佳答案

问题已解决。

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setClassName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity");

关于android - 尝试从其他应用安装 APK 时如何使用默认包安装程序(Android)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18369938/

相关文章:

android - 如果可以的话,使用更具体的更改事件总是更有效。依靠 notifyDataSetChanged 作为最后的手段。回收 View

android - Http在android中发布高分辨率图像

android - 将 parcelable 添加到自定义对象的接口(interface)类

android - 如何通过 android 应用在 google Plus 中共享图像?

linux-kernel - 安装 vmware 工具 : not recognizing path to 3. 8.0-19-generic 内核文件

installation - 安装 Cappuccino (Objective J)

browser - 自动安装 JRE

iphone - 弹性 :Can we develop flex mobile project that runs in both android and iphone

android - 如果通过 CMD 打开,模拟器只有互联网连接

java - Android Intent 不起作用