//通过命令启动
public static void openApp(String string) {
try {
mDevice.executeShellCommand("am start -n " + string);//执行一个shell命令,需要5.0以上手机
mDevice.wait(Until.hasObject(By.pkg(string).depth(0)), 2000);
contentPass("启动app", "openApp", string, "");
} catch (IOException e) {
e.printStackTrace();
}
}
//通过Intent启动app
public static void openApp2(String string) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(string);
Objects.requireNonNull(intent).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
mDevice.wait(Until.hasObject(By.pkg(string).depth(0)), 2000);
}