根据名称关闭,免root
killApp("百度");
function killApp(name) {
let forcedStopStr = ["停", "强", "结束"];
let packageName = app.getPackageName(name);
if (packageName) {
app.openAppSetting(packageName);
text(name).waitFor();
for (var i = 0; i < forcedStopStr.length; i++) {
if (textContains(forcedStopStr[i]).exists()) {
let forcedStop = textContains(forcedStopStr[i]).findOne();
if (forcedStop.enabled()) {
forcedStop.click();
text("确定").findOne().click();
toastLog(name + "已结束运行");
sleep(800);
back();
break;
} else {
toastLog(name + "不在后台运行!");
back();
break;
}
}
}
} else {
toastLog("应用不存在");
}
}