请教:经常没反应=>app.launchApp("某音")
function qdapp(packageName, name) {
home();
sleep(500);
if (app.launch(packageName)) {
sleep(5000);
toast("成功启动=" + name);
console.log("启动currentPackage=" + currentPackage());
console.log("启动currentActivity=" + currentActivity());
if (currentPackage() != packageName) {
sleep(500);
launch(packageName);
sleep(5000);
}
var i = 1;
while (currentPackage() != packageName) {
sleep(1000);
console.log("检测到没有启动,所以进入循环状态去启动!!!");
console.log("启动currentPackage=" + currentPackage());
var jmapp = className("android.widget.TextView").text(name).find();
if (!jmapp.empty() && jmapp.length) {
console.log("获取=" + jmapp[0].clickable());
if (jmapp[0].clickable() == true && i == 1) {
jmapp[0].clicK();
}
if (jmapp[0].clickable() == false && i == 1) {
var bounds = jmapp[0].parent().bounds();
var centerX = (bounds.left + bounds.right) / 2;
var centerY = (bounds.top + bounds.bottom) / 2;
click(centerX, centerY);
}
}
var jmapp2 = className("android.widget.TextView").desc(name).find();
if (!jmapp2.empty() && jmapp2.length) {
console.log("获取=" + jmapp2[0].clickable());
if (jmapp2[0].clickable() == true && i == 2) {
jmapp2[0].clicK();
}
if (jmapp2[0].clickable() == false && i == 2) {
var bounds = jmapp2[0].parent().bounds();
var centerX = (bounds.left + bounds.right) / 2;
var centerY = (bounds.top + bounds.bottom) / 2;
click(centerX, centerY);
}
}
if (currentPackage() != packageName && i == 3) {
toast("无法启动,请把" + name + "图标放到主页,或者自己手动打开。");
i = 1;
}
i += 1;
sleep(5000);
console.log("启动currentPackage=" + currentPackage());
}
} else {
toast("失败,请查看是否有开启权限!" + packageName);
}
}
其中:packageName=启动app的包名, name=app桌面上的名称,启动的地方调用这个函数即可,但是要把app的图标都放到home主页去。