代码段
下载文件
var url = "http://xxx/1.mp4";
var res = http.get(url);
if(res.statusCode != 200){
toast("请求失败");
}
var path = "/sdcard/1.mp4";
files.writeBytes(path, res.body.bytes());
toast("下载成功");
app.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,android.net.Uri.fromFile(java.io.File(path))));
等待指定页面
waitForActivity("com.tencent.mm.plugin.brandservice.ui.BrandServiceIndexUI");
find
comment = desc("评论").find();
if (!comment.empty()) {
comment.forEach(item => {
var b = item.click();
console.log(b ? "点击评论成功" : "点击评论失败");
sleep(1000);
if (className("android.widget.TextView").text("赞").exists()) {
className("android.widget.TextView").text("赞").findOne().parent().click();
sleep(1000);
}
})
}
文件夹
files.write("/sdcard/xx.txt", "content---xxxx",encoding = "utf-8");
files.removeDir(downloadpath);
files.create(downloadpath);
下载
var img = images.load(url);
if(img.toString() == "null"){
toast("图片下载失败");
}
else{
toast("开始下载图片");
sleep(500);
var path = "xxx.jpg";
images.save(img,path,"jpg",100);
}
http
var r= http.get("http://xxurl") ;
if(r.statusCode == 200)
{
obj = r.body.json();
}
else
{
alert("请求数据出错");
return false;
}