java - android:使用包安装程序以编程方式安装应用程序

标签 java android installation action package-managers

我正在以编程方式安装 Android 应用程序。出现一个对话框“Complete Action Using”。 “Package Installer”之间有许多选项可用。如何在不要求用户选择的情况下隐式选择“Package Installer”?

编辑 我使用的代码是:

 Intent intent = new Intent();
intent .setDataAndType(Uri.fromFile(new File("/mnt/sdcard/download/App.apk")),"application/vnd.android.package-archive");
startActivity(intent);

最佳答案

我正在使用此代码来完成该任务。我猜你错过了添加类型?

Uri fileUri = Uri.fromFile(myFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri, "application/vnd.android.package-archive");
startActivity(intent);

关于java - android:使用包安装程序以编程方式安装应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11137439/

相关文章:

java - 我的表没有在 Sqlite 中创建(Toast for dataNotInserted)....下面的代码 fragment

java - 由于删除了 java.orig 文件,tomcat 无法发布

java - Gradle Tomcat 插件依赖

java - 将 utf-8 字符添加到字符串数组中

android - 让 Glide 作为所有类的单例工作

android - 谷歌安卓市场搜索结果

deployment - 标准 "Installation"实际上做了什么?

java - 无法使用 Microsoft SQL Server 和 Javax.Persistence 解析 Java 中的列 [名称]

linux - 如何强制RPM在单个目录中安装文件,可能吗?

installation - 如何共享在 pytest/unittest 测试中具有作为 session 范围的 fixture 中创建的 session 对象