可以从自定义Android应用程序中以编程方式安装动态下载的apk。
当前回答
UpdateNode provides an API for Android to install APK packages from inside another App. You can just define your Update online and integrate the API into your App - that's it. Currently the API is in Beta state, but you can already do some tests yourself. Beside that, UpdateNode offers also displaying messages though the system - pretty useful if you want to tell something important to your users. I am part of the client dev team and am using at least the message functionality for my own Android App.
这里介绍了如何集成API
其他回答
您可以轻松启动市场链接或安装提示:
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file:///path/to/your.apk"),
"application/vnd.android.package-archive");
startActivity(promptInstall);
源
Intent goToMarket = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("market://details?id=com.package.name"));
startActivity(goToMarket);
源
但是,没有用户的明确许可,你不能安装。apks;除非设备和您的程序已经扎根。
我只是想分享一个事实,我的apk文件保存到我的应用程序“数据”目录,我需要更改apk文件的权限,使其成为世界可读的,以便允许它以这种方式安装,否则系统会抛出“解析错误:解析包存在问题”;所以使用@Horaceman的解决方案,使:
File file = new File(dir, "App.apk");
file.setReadable(true, false);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
试试这个 -在舱单上填写:
uses-permission android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions"
编写代码:
File sdCard = Environment.getExternalStorageDirectory();
String fileStr = sdCard.getAbsolutePath() + "/Download";// + "app-release.apk";
File file = new File(fileStr, "app-release.apk");
Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(promptInstall);
另一种解决方案不需要硬编码接收应用程序,因此更安全:
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setData( Uri.fromFile(new File(pathToApk)) );
startActivity(intent);
首先在AndroidManifest.xml中添加以下行:
<uses-permission android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions" />
然后使用以下代码安装apk:
File sdCard = Environment.getExternalStorageDirectory();
String fileStr = sdCard.getAbsolutePath() + "/MyApp";// + "app-release.apk";
File file = new File(fileStr, "TaghvimShamsi.apk");
Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(promptInstall);
推荐文章
- Visual Studio代码- URI的目标不存在" package:flutter/material.dart "
- Tab在平板设备上不采用全宽度[使用android.support.design.widget.TabLayout]
- 我们应该用RecyclerView来代替ListView吗?
- App-release-unsigned.apk没有签名
- 如何在对话框中创建编辑文本框
- 在viewpager中获取当前Fragment实例
- 如何右对齐小部件在水平线性布局安卓?
- 如何创建EditText与十字(x)按钮在它的结束?
- 电话:用于文本输入的数字键盘
- 如何设置不透明度(Alpha)的视图在Android
- Flutter:升级游戏商店的版本代码
- Android构建脚本库:jcenter VS mavencentral
- Android -包名称约定
- 在Android上以编程方式安装应用程序
- 如何膨胀一个视图与布局