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主页去。
代码:
console.log("开始加载图片:" + urlthumb);
var img = images.load(urlthumb, function(err, result) {
if (err) {
console.error("加载图片失败:" + err.message);
return;
}
console.log("图片加载成功,开始保存:" + photoPath);
images.save(result, photoPath, { format: 'jpeg', quality: 90 }, function(err) {
if (err) {
console.error("保存图片失败:" + err.message);
return;
}
console.log("图片保存成功!");
});
});
报错结果:
16:38:35.535/D: 开始加载图片:https://www.gamejoyfull.com/uploads/gamepic/20230710/d1786099a853a1040f85a699b89a7f5f.jpeg
16:38:35.578/E: Can't find method com.stardust.autojs.runtime.api.Images.load(string,function). ([remote]test#59)
Can't find method com.stardust.autojs.runtime.api.Images.load(string,function).
at ImgSearch ([remote]test:59:0)
at main ([remote]test:8:0)
at [remote]test:4:0