实例介绍
【实例简介】
【实例截图】
【实例截图】
【核心代码】
目录
Auto.js文档综述 26
Q & A 27
如何定时运行脚本 27
定时任何如何获取外部参数 28
如何把图片和脚本一起打包,或者打包多个脚本 28
如何使打包的应用不显示主界面 28
Auto.js自带的模块和函数中没有的功能如何实现 29
关于本文档 30
API稳定性 31
如何阅读本文档 31
应用—App 33
app.versionCode 33
app.versionName 33
app.autojs.versionCode 33
app.autojs.versionName 34
app.launchApp(appName) 34
app.launch(packageName) 34
app.launchPackage(packageName) 34
app.getPackageName(appName) 34
app.getAppName(packageName) 35
app.openAppSetting(packageName) 35
app.viewFile(path) 35
app.editFile(path) 35
app.uninstall(packageName) 36
app.openUrl(url) 36
app.sendEmail(options) 36
app.startActivity(name) 37
应用进阶: 意图Intent 37
app.intent(options) 38
app.startActivity(options) 40
app.sendBroadcast(options) 40
app.startService(options) 40
app.sendBroadcast(name) 41
app.intentToShell(options) 41
app.parseUri(uri) 41
app.getUriForFile(path) 42
全局变量与全局函数 42
sleep(n) 42
currentPackage() 43
currentActivity() 43
setClip(text) 43
getClip() 43
toast(message) 43
toastLog(message) 44
waitForActivity(activity[, period = 200]) 45
waitForPackage(package[, period = 200]) 45
exit() 45
random(min, max) 45
random() 45
requiresApi(api) 46
requiresAutojsVersion(version) 46
runtime.requestPermissions(permissions) 47
runtime.loadJar(path) 47
runtime.loadDex(path) 48
context 48
控制台—Console 48
console.show() 48
console.hide() 48
console.clear() 49
console.log([data][, ...args]) 49
console.verbose([data][, ...args]) 49
console.info([data][, ...args]) 49
console.warn([data][, ...args]) 50
console.error([data][, ...args]) 50
console.assert(value, message) 50
console.time([label]) 50
console.timeEnd(label) 51
console.trace([data][, ...args]) 51
console.input(data[, ...args]) 52
console.rawInput(data[, ...args]) 52
console.setSize(w, h) 53
console.setPosition(x, y) 53
console.setGlobalLogConfig(config) 53
print(text) 54
基于坐标的操作 54
安卓7.0以上的触摸和手势模拟 55
RootAutomator 58
使用root权限点击和滑动的简单命令 60
设备—Device 61
device.width 62
device.height 62
device.buildId 62
device.broad 62
device.brand 62
device.device 63
deivce.model 63
device.product 63
device.bootloader 63
device.hardware 63
device.fingerprint 63
device.serial 64
device.sdkInt 64
device.incremental 64
device.release 64
device.baseOS 64
device.securityPatch 64
device.codename 65
device.getIMEI() 65
device.getAndroidId() 65
device.getMacAddress() 65
device.getBrightness() 65
device.getBrightnessMode() 66
device.setBrightness(b) 66
device.setBrightnessMode(mode) 66
device.getMusicVolume() 66
device.getNotificationVolume() 66
device.getAlarmVolume() 66
device.getMusicMaxVolume() 67
device.getNotificationMaxVolume() 67
device.getAlarmMaxVolume() 67
device.setMusicVolume(volume) 67
device.setNotificationVolume(volume) 67
device.setAlarmVolume(volume) 67
device.getBattery() 68
device.isCharging() 68
device.getTotalMem() 68
device.getAvailMem() 68
device.isScreenOn() 68
device.wakeUp() 68
device.wakeUpIfNeeded() 69
device.keepScreenOn([timeout]) 69
device.keepScreenDim([timeout]) 69
device.cancelKeepingAwake() 70
device.vibrate(millis) 70
device.cancelVibration() 70
对话框—Dialogs 70
dialogs.alert(title[, content, callback]) 71
dialogs.confirm(title[, content, callback]) 72
dialogs.rawInput(title[, prefill, callback]) 73
dialogs.input(title[, prefill, callback]) 73
dialogs.prompt(title[, prefill, callback]) 74
dialogs.select(title, items, callback) 74
dialogs.singleChoice(title, items[, index, callback]) 75
dialogs.multiChoice(title, items[, indices, callback]) 75
dialogs.build(properties) 76
Dialog 81
dialog.getProgress() 88
dialog.getMaxProgress() 88
dialog.getActionButton(action) 89
脚本引擎—Engines 89
engines.execScript(name, script[, config]) 89
engines.execScriptFile(path[, config]) 91
engines.execAutoFile(path[, config]) 91
engines.stopAll() 91
engines.stopAllAndToast() 92
engines.myEngine() 92
engines.all() 92
ScriptExecution 92
ScriptExecution.getEngine() 92
ScriptExecution.getConfig() 92
ScriptEngine 93
ScriptEngine.forceStop() 93
ScriptEngine.cwd() 93
ScriptEngine.getSource() 93
ScriptEngine.emit(eventName[, ...args]) 93
e.getEngine().emit("say", "你好"); 94
ScriptConfig 94
delay 94
interval 94
loopTimes 94
getPath() 95
事件与监听—Events 95
events.emitter() 96
events.observeKey() 96
events.onKeyDown(keyName, listener) 96
events.onKeyUp(keyName, listener) 97
events.onceKeyDown(keyName, listener) 98
events.onceKeyUp(keyName, listener) 98
events.removeAllKeyDownListeners(keyName) 98
events.removeAllKeyUpListeners(keyName) 98
events.setKeyInterceptionEnabled([key, ]enabled) 98
events.observeTouch() 99
events.setTouchEventTimeout(timeout) 99
events.getTouchEventTimeout() 100
events.onTouch(listener) 100
events.removeAllTouchListeners() 100
事件: 'key' 101
事件: 'key_down' 102
事件: 'key_up' 102
事件: 'exit` 102
events.observeNotification() 103
events.observeToast() 103
事件: 'toast' 104
事件: 'notification' 104
Notification 104
KeyEvent 106
keys 107
EventEmitter 107
events.broadcast: 脚本间广播 115
悬浮窗—Floaty 115
floaty.window(layout) 116
floaty.rawWindow(layout) 117
w.setPosition(500, 500); 117
floaty.closeAll() 118
FloatyWindow 118
FloatyRawWindow 119
w.setSize(-1, -1); 120
w.setTouchable(false); 120
w.setSize(-1, -1); 121
文件系统—Files 122
files.isFile(path) 122
files.isDir(path) 122
files.isEmptyDir(path) 122
files.join(parent, child) 123
files.create(path) 123
files.createWithDirs(path) 123
files.exists(path) 123
files.ensureDir(path) 123
files.read(path[, encoding = "utf-8"]) 124
files.readBytes(path) 124
files.write(path, text[, encoding = "utf-8"]) 125
files.writeBytes(path, bytes) 125
files.append(path, text[, encoding = 'utf-8']) 125
files.appendBytes(path, text[, encoding = 'utf-8']) 126
files.copy(fromPath, toPath) 126
files.move(fromPath, toPath) 126
files.rename(path, newName) 126
files.renameWithoutExtension(path, newName) 126
files.getName(path) 127
files.getNameWithoutExtension(path) 127
files.getExtension(path) 127
files.remove(path) 127
files.removeDir(path) 127
files.getSdcardPath() 128
files.cwd() 128
files.path(relativePath) 128
files.listDir(path[, filter]) 128
open(path[, mode = "r", encoding = "utf-8", bufferSize = 8192]) 129
ReadableTextFile 129
PWritableTextFile 130
HTTP 131
http.get(url[, options, callback]) 131
http.post(url, data[, options, callback]) 133
http.postJson(url[, data, options, callback]) 134
r = http.postJson(url, { 135
http.postMultipart(url, files[, options, callback]) 135
http.request(url[, options, callback]) 136
Response 137
colors 139
colors.toString(color) 139
colors.red(color) 140
colors.green(color) 140
colors.blue(color) 140
colors.alpha(color) 140
colors.rgb(red, green, blue) 140
colors.argb(alpha, red, green, blue) 141
colors.parseColor(colorStr) 141
colors.isSimilar(color2, color2[, threshold, algorithm]) 141
colors.equals(color1, color2) 141
colors.BLACK 142
colors.DKGRAY 142
colors.GRAY 142
colors.LTGRAY 142
colors.WHITE 142
colors.RED 142
colors.GREEN 142
colors.BLUE 142
colors.YELLOW 143
colors.CYAN 143
colors.MAGENTA 143
colors.TRANSPARENT 143
Images 143
图片处理 144
images.read(path) 144
images.load(url) 144
images.copy(img) 144
images.save(image, path[, format = "png", quality = 100]) 144
images.fromBase64(base64) 145
images.toBase64(img[, format = "png", quality = 100]) 145
images.fromBytes(bytes) 145
images.toBytes(img[, format = "png", quality = 100]) 146
images.clip(img, x, y, w, h) 146
images.resize(img, size[, interpolation]) 146
images.scale(img, fx, fy[, interpolation]) 147
images.rotate(img, degress[, x, y]) 147
images.concat(img1, image2[, direction]) 148
images.grayscale(img) 148
image.threshold(img, threshold, maxVal[, type]) 148
images.adaptiveThreshold(img, maxValue, adaptiveMethod, thresholdType, blockSize, C) 149
images.cvtColor(img, code[, dstCn]) 150
images.inRange(img, lowerBound, upperBound) 150
images.interval(img, color, interval) 150
images.blur(img, size[, anchor, type]) 151
images.medianBlur(img, size) 152
images.gaussianBlur(img, size[, sigmaX, sigmaY, type]) 152
images.matToImage(mat) 152
找图找色 152
images.requestScreenCapture([landscape]) 153
第一次使用该函数会弹出截图权限请求,建议选择“总是允许”。 153
images.captureScreen() 154
images.captureScreen(path) 155
images.pixel(image, x, y) 155
images.findColor(image, color, options) 155
images.findColorInRegion(img, color, x, y[, width, height, threshold]) 157
images.findColorEquals(img, color[, x, y, width, height]) 157
images.findMultiColors(img, firstColor, colors[, options]) 158
images.detectsColor(image, color, x, y[, threshold = 16, algorithm = "diff"]) 159
images.findImage(img, template[, options]) 161
images.findImageInRegion(img, template, x, y[, width, height, threshold]) 162
images.matchTemplate(img, template, options) 163
MatchingResult 163
matches 163
points 164
first() 164
第一个匹配结果。如果没有任何匹配,则返回null。 164
last() 164
leftmost() 164
topmost() 164
rightmost() 164
bottommost() 165
best() 165
worst() 165
sortBy(cmp) 165
Image 165
Image.getWidth() 165
Image.getHeight() 166
Image.saveTo(path) 166
Image.pixel(x, y) 166
Point 166
Point.x 166
Point.y 166
Canvas 167
canvas.drawARGB(a, r, g, b) 168
canvas.draw 168
Keys 168
back() 168
home() 168
powerDialog() 168
notifications() 169
quickSettings() 169
recents() 169
splitScreen() 169
Home() 169
Back() 169
Power() 169
Menu() 170
VolumeUp() 170
VolumeDown() 170
Camera() 170
Up() 170
Down() 170
Left() 170
Right() 170
OK() 170
Text(text) 171
KeyCode(code) 171
附录: KeyCode对照表 171
Media 173
media.scanFile(path) 174
media.playMusic(path[, volume, looping]) 175
media.musicSeekTo(msec) 175
media.pauseMusic() 176
media.resumeMusic() 176
media.stopMusic() 176
media.isMusicPlaying() 176
media.getMusicDuration() 176
media.getMusicCurrentPosition() 176
module (模块) 177
基于控件的操作 178
auto([mode]) 179
auto.waitFor() 180
auto.setMode(mode) 180
SimpleActionAutomator 180
click(text[, i]) 180
click(left, top, bottom, right) 181
longClick(text[, i])) 181
scrollUp([i]) 182
scrollDown([i]) 182
setText([i, ]text) 182
input([i, ]text) 183
UiSelector 183
selector() 187
UiSelector.text(str) 187
UiSelector.textContains(str) 187
UiSelector.textStartsWith(prefix) 187
UiSelector.textEndsWith(suffix) 188
UiSelector.textMatches(reg) 188
UiSelector.desc(str) 188
UiSelector.descContains(str) 189
UiSelector.descStartsWith(prefix) 189
UiSelector.descEndsWith(suffix) 189
UiSelector.descMatches(reg) 189
UiSelector.id(resId) 189
UiSelector.idContains(str) 190
UiSelector.idStartsWith(prefix) 190
UiSelector.idEndsWith(suffix) 190
UiSelector.idMatches(reg) 190
UiSelector.className(str) 191
UiSelector.classNameContains(str) 191
UiSelector.classNameStartsWith(prefix) 192
UiSelector.classNameEndsWith(suffix) 192
UiSelector.classNameMatches(reg) 192
UiSelector.packageName(str) 192
UiSelector.packageNameContains(str) 193
UiSelector.packageNameStartsWith(prefix) 193
UiSelector.packageNameEndsWith(suffix) 193
UiSelector.packageNameMatches(reg) 193
UiSelector.bounds(left, top, right, buttom) 193
UiSelector.boundsInside(left, top, right, buttom) 194
UiSelector.boundsContains(left, top, right, buttom) 194
UiSelector.drawingOrder(order) 195
UiSelector.clickable([b = true]) 195
UiSelector.longClickable([b = true]) 195
UiSelector.checkable([b = true]) 195
UiSelector.selected([b = true]) 196
UiSelector.enabled([b = true]) 196
UiSelector.scrollable([b = true]) 196
UiSelector.editable([b = true]) 196
UiSelector.multiLine([b = true]) 197
UiSelector.findOne() 197
UiSelector.findOne(timeout) 197
UiSelector.findOnce() 198
UiSelector.findOnce(i) 198
UiSelector.find() 198
UiSelector.untilFind() 199
UiSelector.exists() 199
UiSelector.waitFor() 200
UiSelector.filter(f) 200
UiObject 200
UiObject.click() 201
UiObject.longClick() 201
UiObject.setText(text) 201
UiObject.copy() 201
UiObject.cut() 202
UiObject.paste() 202
UiObject.setSelection(start, end) 203
UiObject.scrollForward() 203
UiObject.scrollBackward() 203
UiObject.select() 204
UiObject.collapse() 204
UiObject.expand() 204
UiObject.show() 204
UiObject.scrollUp() 204
UiObject.scrollDown() 204
UiObject.scrollLeft() 204
UiObject.scrollRight() 204
children() 205
childCount() 205
child(i) 205
parent() 206
bounds() 206
boundsInParent() 206
drawingOrder() 206
id() 207
text() 207
findByText(str) 207
findOne(selector) 207
find(selector) 208
UiCollection 209
UiCollection.size() 210
UiCollection.get(i) 210
UiCollection.each(func) 210
empty() 210
nonEmpty() 211
UiCollection.find(selector) 211
UiCollection.findOne(selector) 211
Rect 211
Rect.left 211
Rect.right 212
Rect.top 212
Rect.bottom 212
Rect.centerX() 212
Rect.centerY() 212
Rect.width() 212
Rect.height() 212
Rect.contains(r) 213
Rect.intersect(r) 213
UiSelector进阶 213
Sensors 213
sensors.register(sensorName[, delay]) 215
sensors.unregister(emitter) 217
sensors.unregisterAll() 217
sensors.ignoresUnsupportedSensor 217
事件: 'unsupported_sensor' 218
SensorEventEmitter 218
事件: 'change' 218
事件: 'accuracy_change' 220
shell函数 221
shell(cmd[, root]) 221
Shell 222
new Shell(root) 222
Shell.exec(cmd) 222
Shell.exit() 222
Shell.exitAndWaitFor() 223
Shell.setCallback(callback) 223
附录: shell命令简介 224
am命令 224
应用包名 230
pm命令 230
其他命令 234
Threads 238
threads.start(action) 238
threads.shutDownAll() 239
threads.currentThread() 239
threads.disposable() 239
threads.atomic([initialValue]) 240
threads.lock() 240
Thread 240
Thread.interrupt() 241
Thread.join([timeout]) 241
isAlive() 242
waitFor() 242
Thread.setTimeout(callback, delay[, ...args]) 242
Thread.setInterval(callback, delay[, ...args]) 243
Thread.setImmediate(callback[, ...args]) 243
Thread.clearInterval(id) 244
Thread.clearTimeout(id) 244
Thread.clearImmediate(id) 244
线程安全 244
sync(func) 249
线程通信 249
Timers 252
setInterval(callback, delay[, ...args]) 254
setTimeout(callback, delay[, ...args]) 254
setImmediate(callback[, ...args]) 254
clearInterval(id) 255
clearTimeout(id) 255
clearImmediate(id) 255
用户界面: UI 255
视图: View 258
w 259
h 260
id 260
gravity 261
layout_gravity 262
margin 262
marginLeft 264
marginRight 264
marginTop 264
marginBottom 264
padding 265
paddingLeft 266
paddingRight 266
paddingTop 266
paddingBottom 266
bg 266
alpha 267
foreground 267
minHeight 267
minWidth 267
visbility 267
rotation 268
transformPivotX 268
transformPivotY 268
style 268
文本控件: text 269
text 269
textColor 269
textSize 269
textStyle 269
lines 270
maxLines 270
typeface 270
ellipsize 271
ems 271
autoLink 271
按钮控件: button 272
输入框控件: input 272
hint 273
textColorHint 274
textSizeHint 274
inputType 274
password 275
numeric 275
phoneNumber 275
digits 275
singleLine 276
图片控件: img 276
src 276
tint 278
scaleType 278
radius 279
radiusTopLeft 279
radiusTopRight 279
radiusBottomLeft 279
radiusBottomRight 279
borderWidth 279
borderColor 280
circle 280
垂直布局: vertical 280
layout_weight 280
水平布局: horizontal 283
layout_weight 283
线性布局: linear 284
帧布局: frame 284
相对布局: relative 284
勾选框控件: checkbox 284
选择框控件: radio 284
选择框布局: radiogroup 284
开关控件: switch 284
进度条控件: progressbar 285
拖动条控件: seekbar 285
下来菜单控件: spinner 285
时间选择控件: timepicker 285
日期选择控件: datepicker 285
浮动按钮控件: fab 285
标题栏控件: toolbar 285
卡片: card 285
抽屉布局: drawer 285
列表: list 285
Tab: tab 285
ui 285
ui.layout(xml) 285
ui.inflate(xml[, parent]) 286
ui.findView(id) 286
ui.finish() 286
ui.setContentView(view) 286
ui.run(callback) 286
ui.post(callback[, daley]) 286
ui.statusBarColor(color) 286
ui.showPopupMenu(view, menu) 286
尺寸的单位: Dimension 286
Drawables 286
颜色 286
好例子网口号:伸出你的我的手 — 分享!
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论