//安装apk,传入路径
public static void installApk(String string) {
try {
Log.e(TAG, "开始安装app:" + string);
mDevice.executeShellCommand("pm install -t -r -d " + string);//-t 允许测试apk被安装 -r 重新安装应用,且保留应用数据 -d 允许降级安装(同一应用低级换高级)
Log.e(TAG, "安装成功app:" + string);
sleep(2000);
contentPass("安装app", "installApk", string, "");
} catch (IOException e) {
contentFail("安装app", "installApk", string, "");
e.printStackTrace();
}
}
//卸载apk,传入包名
public static void unInstallApk(String string) {
if (isAppInstalled(string)) {
try {
Log.e(TAG, "开始卸载app:" + string);
mDevice.executeShellCommand("pm uninstall " + string);
Log.e(TAG, "卸载成功app:" + string);
contentPass("卸载app", "unInstallApk", string, "");
} catch (IOException e) {
contentFail("卸载app", "unInstallApk", string, "");
e.printStackTrace();
}
} else {
Log.e(TAG, "要卸载的app不存在: " + string);
}
}