说明
本文提供的代码仅供参考。不建议用于生产环境。
可能有些地方在最新版本的Auto.js上面需要做修改,才能运行。
Auto.js简介
Auto.js是利用安卓系统的“辅助功能”实现类似于按键精灵一样,可以通过代码模拟一系列界面动作的辅助工作。
与“按键精灵”不同的是,它的模拟动作并不是简单的使用在界面定坐标点来实现,而是类似与win一般,找窗口句柄来实现的。
Auto.js使用JavaScript作为脚本语言,目前使用Rhino 1.7.7.2作为脚本引擎,支持ES5与部分ES6特性。
开发文档
Auto.js Pro开发文档
文档尚在完善中,可能有文档描述和代码实际行为有出入的情况。
为什么要使用Auto.js Pro开发脚本,有什么特点?
吸引我使用Auto.js Pro的原因有很多。最主要的几个原因是:
- Auto.js Pro能开发免ROOT的安卓脚本
- Auto.js Pro基于节点操作,能开发全分辨率的脚本,自动适配各种安卓机型
- Auto.js Pro丰富的UI组件,能自定义各种样式的安卓界面
- Auto.js Pro使用的javascript的语法比较优雅,代码可读性强
- Auto.js Pro的命令库非常的丰富,接口比较多
- Auto.js Pro脚本文件体积比较小。1000行的代码,打包后的apk文件只有3-5M,还没有广告
推荐教程
Auto.js Pro安卓全分辨率免ROOT引流脚本开发视频教程(HD超清1080p)
示例代码
//此代码由飞云脚本圈整理提供(www.feiyunjs.com)
"ui";
ui.layout(
<vertical w="*" h="*" gravity="center" >
<button id="notify" w="auto" h="auto" text="发送通知" textSize="22sp" padding="12dp" />
<button id="cancel" w="auto" h="auto" text="去除通知" textSize="22sp" padding="12dp" />
</vertical>
);
ui.notify.on("click", () => {
var manager = context.getSystemService(android.app.Service.NOTIFICATION_SERVICE);
var notification;
if (device.sdkInt >= 26) {
var channel = new android.app.NotificationChannel("channel_id", "channel_name", android.app.NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(0xff0000);
channel.setShowBadge(false);
manager.createNotificationChannel(channel);
notification = new android.app.Notification.Builder(context, "channel_id")
.setContentTitle("通知栏标题"+new date())
.setContentText("这是消息的内容")
.setWhen(new Date().getTime())
.setSmallIcon(org.autojs.autojs.R.drawable.autojs_material)
.setTicker("这是状态栏显示的内容")
.build();
} else {
notification = new android.app.Notification.Builder(context)
.setContentTitle("通知栏标题")
.setContentText("这是消息的内容")
.setWhen(new Date().getTime())
.setSmallIcon(org.autojs.autojs.R.drawable.autojs_material)
.setTicker("这是状态栏显示的内容")
.build();
}
manager.notify(1, notification);
});
ui.cancel.on("click", () => {
var manager = context.getSystemService(android.app.Service.NOTIFICATION_SERVICE);
manager.cancelAll();
// manager.cancel(1);
});