android - 使用 Intent 构建、安装 APK
问题描述
当我尝试使用以下方式安装 APK 时:
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE);
installIntent.setData(Uri.fromFile(true_path));
startActivity(installIntent);
我收到错误:
file:///...app-debug.apk exposed beyond app through Intent.getData()
我相信意图不能使用 file:// URI;如何使用 Android Studio 构建 APK,以便 Intent 可以使用它?
解决方案
正确的做法是
File file = new File(dir, "App.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(intent);
推荐阅读
- javascript - 如何在 javascript 中将 python 类 str 转换为字典
- google-chrome - chrome declarativeNetRequest api - 规则集更新
- python - numpy中张量的矩阵向量乘法
- eclipse - Eclipse 在 ABAP 程序启动时显示登录屏幕
- laravel - 获取在 Laravel API 中执行的数据库语句列表
- python - Python比较和区分自定义对象
- php - 在 Laravel 8 中运行多个 PHPUnit 测试时出错
- nginx - nginx 可以通过哪些方式向我的应用服务器发送请求?
- java - wsdl2java 生成带有长名称的 java 类
- python - Python Scrapy OSError: [WinError 123] 文件名、目录名或卷标语法不正确: