android - 如何以编程方式将 .apk 安装到 android 设备中?
问题描述
任何人都可以帮助如何以编程方式在 android 设备/模拟器中安装 .apk 文件吗?
我尝试了以下方法:
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.executeShellCommand("adb shell pm install -t -r /data/local/tmp/com.example.xxxxx.xxxxxx");
但它不起作用。
我正在使用 UIAutomator 进行 android 本机应用程序自动化测试,在继续执行测试脚本之前,我需要将 .apk 文件安装到 android 设备/模拟器中。
解决方案
executeShellCommand
在您的设备内运行。不需要adb shell
了。
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.executeShellCommand("pm install -t -r /data/local/tmp/com.example.xxxxx.xxxxxx");
推荐阅读
- regex - How do I perform a regex test in bash that starts with spaces and includes quotation marks?
- c# - DocuSign 选项卡中的复选框问题
- android - React-native 应用程序在 android studio 中崩溃而没有错误
- python - Python:当我尝试将字符串转换为列表时,字符串索引出或范围在while循环中
- sql-server - Gitlab-CI 无法连接到基于 Windows 的容器上的服务
- python - 如何将 csv 文件作为字典读取,以便键是元组
- html - 显示 flex 在 Material UI Grid Item 中不起作用
- docker - 在 ubuntu 容器中运行 docker
- reactjs - 单击 testcafe 中的范围下拉菜单
- xsl-fo - 带有分页符和动态内容的 XSL-FO 动态表格宽度