如何以编程方式将.apk安装到android设备?

问题描述 投票:-1回答:3

任何人都可以帮助如何以编程方式在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原生app自动化测试,我需要在继续执行测试脚本之前将.apk文件安装到android设备/模拟器中。

android install uiautomator
3个回答
1
投票

executeShellCommand在你的设备内运行。再也不需要adb shell了。

UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.executeShellCommand("pm install -t -r /data/local/tmp/com.example.xxxxx.xxxxxx");

0
投票

您可以使用以下代码从命令行安装应用程序

adb install example.apk

-1
投票
Before execute `adb shell pm install`, run "adb root" command firstly.

如果您植入设备,则可以省略此步骤。

© www.soinside.com 2019 - 2024. All rights reserved.