### Run Pinduoduo and Scroll Example Source: https://www.aznfz.com/document/sample This script demonstrates launching the Pinduoduo app and performing three scroll actions. It includes error handling for app launch failures and logs the progress of scrolling and task completion. This is a basic example for getting started with app automation. ```javascript function main() { if (1 == launchApp('com.xunmeng.pinduoduo', 'txt:个人中心|txt:多多视频')) { console.log('进入拼多多成功'); var index = 0; while (index < 3) { scroll('up', {distance: Math.random() * 0.5 + 0.45, duration: parseInt(Math.random() * 200 + 300), afterWait: 3000}); ++index; console.log('滚动:' + index); } console.log('任务结束,退出'); } else { console.log('启动拼多多失败'); } } ``` -------------------------------- ### Execute 'ls' command using Shizuku Source: https://www.aznfz.com/document/shizuku This example demonstrates how to initialize Shizuku, connect to the service, and execute the 'ls' command to list files and folders in the current directory. It requires the Shizuku app to be installed and configured. ```javascript function main() { shizuku.init(); if (shizuku.connect()) { var r = shizuku.execCmd('ls') console.log('exe r:' + r) } console.log('end') } ``` -------------------------------- ### Thread Class Example Source: https://www.aznfz.com/document/thread Demonstrates the basic usage of the Thread class, including creating a new thread, starting it with a function and parameters, and defining the function to be executed in the thread. ```javascript function main() { var t = new Thread(); // 注意这里参数填func不是func(); t.start(func, [10, 20]); } function func(a, b) { // a,b的值分别为start函数传递过来的10,20 console.log('exe thread:' + calc(a, b)); } function calc(a, b) { return a + b; } ``` -------------------------------- ### Automate App Installation and Launch Source: https://www.aznfz.com/document/sample This script automates the process of installing, updating, and launching an application. It checks if the app is installed, updates it if a newer version is available, and then launches it. The script includes logic for handling installation prompts and permissions, with specific testing on Xiaomi devices. It returns true if the app is successfully launched. ```javascript // app不存在则安装,版本低则更新,最后再启动app function main(packageName, autoInstall=true, checkUpdate=true, afterWait=6000) { var result = false, version = getAppVersion(packageName), appName = getAppName(packageName); if (appName == '') { console.log('没有安装app'); if (autoInstall) { if (installApp(packageName)) { result = 1 == launchApp(packageName); } } } else { if (checkUpdate) { var latestVersion = getLatestAppVersion(packageName); if (latestVersion != '') { var version = getAppVersion(packageName); if (compareVersion(latestVersion, version)) { // update if (!installApp(packageName)) { console.log('安装失败'); } } } } result = 1 == launchApp(packageName); } if (result) { clickByTag('txt:允许', {click: true, maxStep: 8}); sleep(afterWait); } return result; } function compareVersion(newVersion, oldVersion) { if (newVersion && oldVersion) { newVersion = newVersion.trim(); oldVersion = newVersion.trim(); var newArr = newVersion.split('.'), oldArr = oldVersion.split('.'); var size = Math.min(newArr.length, oldArr.length); for (var i = 0; i < size; ++i) { var newV = parseInt(newArr[i]); var oldV = parseInt(oldArr[i]); if (newV > oldV) { return true; } else if (newV < oldV) { break; } } } return false; } function installApp(packageName) { var savedPath = downloadApp(packageName); if (savedPath != '') { if (install(savedPath)) { // 开始点击界面 console.log('开始点击安装界面'); sleep(2000); var findInstall = false, clickInstall = false, startTime = new Date().getTime(); while (!clickInstall && (new Date().getTime() - startTime) < 100000) { var ret = findView('txt*:解析软件包时出现问题|id:com.miui.packageinstaller:id/install_btn|txt:继续安装|txt*:无视风险安装|txt:退出登录'); if (ret.length > 0) { if (ret.tag == 'com.miui.packageinstaller:id/install_btn' || ret.tag == '继续安装') { click(ret.views[0], {click: true}); } else if (ret.tag == '退出登录') { break; } else if (ret.tag == '无视风险安装') { var view = ret.views[0]; gestureClick(view.right - 100, (view.top + view.bottom) / 2, {afterWait:1000}); } else { console.log('解析软件包失败'); clickByTag('txt:确定', {click: true}); break; } findInstall = true; } if (findInstall) { ret = findView('txt:确定|id:com.miui.packageinstaller:id/done_button'); if (ret.length > 0) { click(ret.views[0], {click: true}); clickInstall = true; } } } console.log('完成安装:' + clickInstall); return clickInstall; } else { console.log('install failed:'); } } return false; } ``` -------------------------------- ### Start Thread Source: https://www.aznfz.com/document/thread Shows how to start a thread using the start method. This method takes a function to execute and an optional array of parameters. ```javascript var t = new Thread(); t.start(func); ``` -------------------------------- ### UI Functions: Install, Get Control, Create, Open, Close UI Source: https://www.aznfz.com/document/ui_template Provides functions for managing user interfaces, including installation, retrieving UI controls, dynamic creation, opening, and closing UI elements. These functions are essential for building interactive user experiences. ```javascript ui.install(); const control = ui.getControl('button1'); ui.createUI('MyUI'); ui.openUI('MyUI'); ui.closeUI('MyUI'); ``` -------------------------------- ### UI: Install UI Interface Source: https://www.aznfz.com/document/console Installs or sets up a user interface. This function likely initializes UI components or loads necessary resources for the interface to be displayed and used. ```javascript function installUI() { console.log('Installing UI interface...'); // ... UI installation logic } ``` -------------------------------- ### Script Examples Source: https://www.aznfz.com/document/ui_flexbox Provides examples of script usage. ```APIDOC ## Script Examples ### Description This section contains various examples demonstrating how to use the available scripting functionalities. (Currently a placeholder). ``` -------------------------------- ### OpenAPI - Start Device Source: https://www.aznfz.com/document/ui_template Initiates the operation of a specific device. ```APIDOC ## OpenAPI - Start Device ### Description Sends a command to start or activate a specified device. ### Method POST ### Endpoint /openapi/devices/{deviceId}/start ### Parameters #### Path Parameters - **deviceId** (string) - Required - The ID of the device to start. #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message that the start command was sent. #### Response Example ```json { "message": "Start command sent to device device-001." } ``` ``` -------------------------------- ### Start Activity with Intent in JavaScript Source: https://www.aznfz.com/document/global Launches a new activity or opens a page using a URL or scheme. It requires an `Intent` object configured with actions, categories, data, type, class name, and package name. Examples show launching the home screen, specific user profiles, and e-commerce product/shop pages. ```javascript // 显示桌面 var intent = new Intent(); intent.setAction('android.intent.action.MAIN').addCategory('android.intent.category.HOME'); startActivity(intent); // 打开抖音中用户的主页 var intent = new Intent(); intent.setData('snssdk1128://user/detail/111186289832'); startActivity(intent); // 打开淘宝商品页面 var intent = new Intent(); intent.setData('taobao://item.taobao.com/item.htm?id=' + item_id); startActivity(intent); // 打开淘宝店铺首页 var intent = new Intent(); intent.setData('taobao://shop.m.taobao.com/shop/shop_index.htm?shop_id=' + shop_id); startActivity(intent); ``` -------------------------------- ### Start YOLOv8 Model Training Source: https://www.aznfz.com/document/yolo_train Initiates the YOLOv8 object detection model training process. It specifies the training data configuration file, the base model to use (yolov8s.pt), and image size. An alternative command includes specifying the number of epochs. ```bash yolo detect train data=e:/yolotrain/aixin.yaml model=e:/yolotrain/yolov8s.pt imgsz=640 yolo detect train data=e:/yolotrain/aixin.yaml model=e:/yolotrain/yolov8s.pt epochs=100 imgsz=640 ``` -------------------------------- ### DeepSeek Example Source: https://www.aznfz.com/document/big_model Example demonstrating how to use the BigModel with DeepSeek. Requires API key to be stored in custom data. ```APIDOC ## DeepSeek Example ### Description Example demonstrating how to use the BigModel with DeepSeek. Requires API key to be stored in custom data. ### Method `main()` ### Parameters None ### Request Example ```javascript function main() { // Store your DeepSeek API key in custom data with the key 'custom_data_key' var bm = new BigModel(2, 'custom_data_key', '', {temperature: 0.8}); var arr = [{'system':'You are an expert in the field of deep learning'}, {'user':'Implement a simple image classification program using Python language'}]; var ret = bm.invoke(arr); console.log('ret:', ret); } ``` ### Response #### Success Response (200) - **ret** (string) - The response from the DeepSeek model. #### Response Example ```json { "example": "ret: Here is a simple Python program for image classification..." } ``` ``` -------------------------------- ### USB HID Client - Click Function Example Source: https://www.aznfz.com/document/usb This example shows how to use the `usb.click` function to simulate a mouse click at specific coordinates on the connected USB HID device. It first establishes a connection and initializes the screen, then performs a click action. ```script function main() { var b = usb.connect(); if (b) { usbInit(rsScreenWidth, rsScreenHeight) usb.click(100, 200); } } ``` -------------------------------- ### Install Application in JavaScript Source: https://www.aznfz.com/document/global Installs an application on the device from an APK file. It takes the full path to the APK file as a string argument. Ensure the file path is correct and the app has the necessary permissions to install. ```javascript installApp('/sdcard/xx.apk'); ``` -------------------------------- ### Mobile Database Operations Example Source: https://www.aznfz.com/document/db This example demonstrates how to use the Database class to create a table, insert data, query records, and close the database connection. It includes checks for table existence before creation. ```javascript var db = new Database('test'); if (!db.isTableExist('deg')) { db.exeSql(`create table deg(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(45) NULL, type DATETIME(4) NULL)`); } var b = db.exeSql(`insert into deg(name, type) values('afe', 11334)`); console.log('b:' + b) var obj = db.query('select * from deg limit 1') console.log('obj:' + obj) db.close(); ``` -------------------------------- ### Baidu Qianfan Example Source: https://www.aznfz.com/document/big_model Example demonstrating how to use the BigModel with Baidu Qianfan. Requires API key and secret to be stored in custom data. ```APIDOC ## Baidu Qianfan Example ### Description Example demonstrating how to use the BigModel with Baidu Qianfan. Requires API key and secret to be stored in custom data. ### Method `main()` ### Parameters None ### Request Example ```javascript function main() { // Store your Baidu Qianfan API key and secret in custom data with keys 'custom_data_key' and 'custom_data_secret' var bm = new BigModel(1, 'custom_data_key', 'custom_data_secret'); var ret = bm.invoke("What is Binghu intelligent assistant?"); console.log('ret:', ret); } ``` ### Response #### Success Response (200) - **ret** (string) - The response from the Baidu Qianfan model. #### Response Example ```json { "example": "ret: Binghu intelligent assistant is a powerful AI tool..." } ``` ``` -------------------------------- ### OpenAPI - Get Device List Source: https://www.aznfz.com/document/ui_template Retrieves a list of available devices. ```APIDOC ## OpenAPI - Get Device List ### Description Fetches a list of all registered devices. ### Method GET ### Endpoint /openapi/devices ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **devices** (array) - A list of device objects. - **deviceId** (string) - Unique identifier for the device. - **deviceName** (string) - Name of the device. #### Response Example ```json { "devices": [ { "deviceId": "device-001", "deviceName": "Living Room Device" }, { "deviceId": "device-002", "deviceName": "Bedroom Device" } ] } ``` ``` -------------------------------- ### Setup UI Function Source: https://www.aznfz.com/document/ui_function Initializes the UI system. This function must be called first in the main function to ensure the UI is created correctly. It takes no arguments. ```javascript function main() { setupUI(); } ``` -------------------------------- ### Install YOLOv8 and Dependencies Source: https://www.aznfz.com/document/yolo_train Installs YOLOv8 and related libraries using pip with a specified Tsinghua mirror for faster downloads. It configures pip to use the mirror and then installs 'yolo', 'ultralytics', 'ncnn', and 'labelimg'. ```bash pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn pip install yolo==0.3.1 pip install ultralytics==8.2.79 pip install ncnn==1.0.20240410 pip install labelimg ``` -------------------------------- ### Automate App Permission Settings Source: https://www.aznfz.com/document/sample This script aims to automate the process of setting app permissions, specifically focusing on disabling the 'get installed app information' permission. It starts by launching the Android settings app and navigating through menus. The script includes scrolling and searching for specific UI elements. This functionality has been tested on Xiaomi devices, but UI variations on other brands may require adjustments. ```javascript // 禁止app「获取手机中已安装的应用信息」权限 function main(appName) { if (!launchApp('com.android.settings')) { return false; } var ret = findView('txt:设置', {failed: exitPopup, maxStep: 30}); if (ret.length <= 0) { console.error('启动设置程序失败'); return false; } scroll('up', {distance: 0.99, afterWait: 1000}); var result = false, scrollCount = 0, target = 'txt:应用设置|txt:授权管理|'; ``` -------------------------------- ### UI Introduction Source: https://www.aznfz.com/document/ui_radio Provides an overview and introduction to the User Interface (UI) system. Essential reading for understanding UI capabilities. ```markdown # UI Introduction This section covers the basics of the UI framework... ``` -------------------------------- ### UI Function: Install UI Interface Source: https://www.aznfz.com/document/big_model Installs or registers a UI interface, making it available for use within the application. This is typically an initial setup step for a specific UI component or screen. ```javascript function installUIInterface(uiDefinition) { // Implementation to register the UI console.log('UI interface installed.'); } ``` -------------------------------- ### getAppName Source: https://www.aznfz.com/document/global Gets the name of an installed app by its package name. Returns a string. (Mobile-only script) ```APIDOC ## GET /getAppName ### Description Gets the name of an installed app by its package name. Returns a string. (Mobile-only script) ### Method GET ### Endpoint /getAppName ### Parameters #### Query Parameters - **packageName** (string) - Required - The package name of the app. ### Request Example ```javascript var ret = getAppName('com.libra.aznfz'); console.log('ret:' + ret); ``` ### Response #### Success Response (200) - **appName** (string) - The name of the app. #### Response Example ```json { "appName": "AzNFZ App" } ``` ``` -------------------------------- ### Thread API Source: https://www.aznfz.com/document/thread This section covers the Thread API, including its constructor, methods for starting, stopping, getting the thread ID, and joining threads. ```APIDOC ## Thread API ### Description Provides functionality for creating and managing threads. ### Thread Constructor Creates a new Thread object. **Example:** ```javascript var t = new Thread(); ``` ### start Starts the execution of a thread. **Parameters:** * **func** (function) - Required - The function to be executed by the thread. * **params** (array) - Optional - An array of parameters to pass to the thread function. * **stackSize** (integer) - Optional - The stack size for the thread. Defaults to 0 (system default). A value of 12388608 is recommended for OCR operations. **Example:** ```javascript var t = new Thread(); t.start(myFunction, [arg1, arg2]); ``` ### stop Stops the execution of a running thread. **Example:** ```javascript var t = new Thread(); t.start(myFunction); t.stop(); ``` ### getId Retrieves the unique identifier of the thread. **Example:** ```javascript var t = new Thread(); console.log('Thread ID: ' + t.getId()); ``` ### join Waits for the thread to complete its execution. **Parameters:** * **millis** (integer) - Optional - The maximum time in milliseconds to wait for the thread to finish. If omitted, it waits indefinitely. **Example:** ```javascript var t = new Thread(); t.start(myFunction); t.join(); // Waits indefinitely for the thread to finish // or t.join(5000); // Waits up to 5000 milliseconds ``` ``` -------------------------------- ### Initialize and Detect with YoloV8 Source: https://www.aznfz.com/document/yolo This example demonstrates how to initialize the YoloV8 model with a specified model name and category list, and then perform object detection on the current screen. ```javascript function main() { requestScreenShot(); var yolo = new YoloV8(); // model_name替换成自己的模型名(注意不要带后缀名),模型文件为:model_name.param和model_nam.bin。class1,class2为目标的类别名 var b = yolo.init('/sdcard/model_name', ['class1', 'class2']) console.log('b:', b) // 会自动截屏,然后检测截图,识别目标 var r = yolo.detect(); console.log('r', r) } ``` -------------------------------- ### Thread Management Source: https://www.aznfz.com/document/aes Provides functionality for creating, starting, stopping, and managing threads. Includes methods for getting thread IDs and waiting for thread completion. ```javascript const thread = new Thread(() => { // Thread task }); thread.start(); const threadId = thread.getId(); thread.join(); thread.stop(); ``` -------------------------------- ### Get App Name by Package Name Source: https://www.aznfz.com/document/global Retrieves the name of an installed application using its package name. Returns a string. This function is for mobile-only scripts. ```javascript var ret = getAppName('com.libra.aznfz'); console.log('ret:' + ret); ``` -------------------------------- ### Initialize and Connect ADB using JavaScript Source: https://www.aznfz.com/document/adb Demonstrates how to initialize the ADB service, establish a connection, perform a click action, and then close the connection. This function requires Shizuku to be installed and configured. ```javascript function main() { adb.init(); if (adb.connect()) { adb.click(750, 650) } adb.close(); console.log('end') } ``` -------------------------------- ### USB HID Client Communication Example Source: https://www.aznfz.com/document/usb This script demonstrates how to use the UsbClient to communicate with USB HID hardware. It includes functions for connecting, initializing the screen, performing actions like clicking, swiping, and navigating home/back, and sending custom commands. Ensure OTG is enabled and the USB hardware is connected. ```script function main() { var b = usb.connect(); console.log('connect:', b); if (b) { usbInit(rsScreenWidth, rsScreenHeight) // usbRecentApps() // usbSwipe(400, 2000, 600, 1000, 1000) // usbBack(usb) usbHome() // usbClick(800, 650) } console.log('end') } function usbInit(screenWidth, screenHeight) { usb.send([0xe].concat(int2bytes(screenWidth, 2), int2bytes(screenHeight, 2))) sleep(3000) } function usbClick(x, y, duration) { if (null == duration) { duration = 200 } usbMouseMove(x, y); sleep(duration); usbMouseUp(x, y); } function usbMouseMove(x, y) { usb.send([0x9].concat(int2bytes(x, 2), int2bytes(y, 2))) } function usbMouseUp(x, y) { usb.send([0xa].concat(int2bytes(x, 2), int2bytes(y, 2))) } function usbSwipe(x1, y1, x2, y2, duration) { if (null == duration) { duration = 300 } var moveCount = randInt(6, 20) var dTime = parseInt(duration / moveCount); var startX = 0, startY = 0, endX = 0, endY = 0, useCurve = false; if (x1 != x2 && y1 != y2) { if (x1 < x2 && y1 > y2) { startX = x1; startY = y1; endX = x2; endY = y2; useCurve = true; } else if (x1 > x2 && y1 < y2) { startX = x2; startY = y2; endX = x1; endY = y1; useCurve = true; } } if (useCurve) { var x = endX - startX; var y = startY - endY; var a = (endX - startX) / ((endY - startY) * (endY - startY)); var yb = y1; var ya = (y2 - yb) / (moveCount * moveCount); for (var i = 1; i < moveCount; ++i) { var fY = (ya * i * i + yb); var y = parseInt(fY); var x = parseInt(a * (y - startY) * (y - startY) + startX); if (i > 1 && i < moveCount - 1) { x += randInt(0, 5) - 2; y += randInt(0, 5) - 2; } usbMouseMove(usb, x, y) sleep(dTime); } } else { usbMouseMove(usb, x1, y1) var a = (x1 - x2) / (y1 - y2); var b = x1 - a * y1; var yb = y1; var ya = (y2 - yb) / (moveCount * moveCount); for (var i = 1; i < moveCount; ++i) { var fY = (ya * i * i + yb); var y = parseInt(fY); var x = parseInt((a * y + b)); if (i > 1 && i < moveCount - 1) { x += randInt(0, 5) - 2; y += randInt(0, 5) - 2; } usbMouseMove(usb, x, y) sleep(dTime); } } usbMouseMove(usb, x2, y2) sleep(10); usbMouseUp(usb, x2, y2) } function usbHome() { usb.send([0x20]) } function usbBack() { usb.send([0xd]) } function usbRecentApps() { usb.send([0x8, 0x4, 0x2b]) } function usbCopy() { usb.send([0x08, 0x01, 0x06]) } function usbPaste() { usb.send([0x08, 0x01, 0x19]) } function usbCut() { usb.send([0x08, 0x01, 0x1B]) } function usbSelectAll() { usb.send([0x08, 0x01, 0x04]) } ``` -------------------------------- ### USB HID Client - Swipe Function Example Source: https://www.aznfz.com/document/usb This script demonstrates the `usb.swipe` function for simulating a swipe gesture on the USB HID device. It connects to the device, initializes the screen, and then performs a swipe from a starting point to an ending point with a specified duration. ```script function main() { var b = usb.connect(); if (b) { usbInit(rsScreenWidth, rsScreenHeight) usb.swipe(100, 800, 200, 300); } } ``` -------------------------------- ### Generate Build Configuration Metadata (JSON) Source: https://www.aznfz.com/document/autoBuild This JSON metadata describes selected modules and parameters for automated build configurations. It allows for quick replication of identical automated builds by importing this structure. The example shows variable declarations and a sequence of actions including launching an app, scrolling, looping through items, and conditional clicking. ```json { "type": "root", "children": [{ "type": "declareVar", "var": [ { "name": "temp", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "ret", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "view", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "viewContainer", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "tag", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "item", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "index", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "data", "type": "normal", "initType": "string", "initValue": "" }, { "name": "text", "type": "normal", "initType": "string", "initValue": "" } ] }, { "type": "main", "desc": "业务逻辑入口", "debug": false, "params": [], "children": [{ "type": "launchApp", "desc": "启动APP", "debug": false, "packageName": "com.ss.android.article.news", "tag": "txt:首页#", "failed": "", "maxStep": "30", "children": [{ "type": "scroll", "desc": "滚动处理", "class": 1, "debug": false, "direction": "up", "tag": "", "family": [], "descendant": [], "widgetIndex": "0", "minDistance": "0.8", "maxDistance": "0.8", "minScrollCount": "2", "maxScrollCount": "3", "minDuration": "500", "maxDuration": "500", "beforeWait": "1000", "afterWait": "1000" }, { "type": "loop", "desc": "循环处理", "class": 1, "debug": false, "minRunTime": "1", "maxRunTime": "2", "children": [{ "type": "traverse", "desc": "遍历容器", "class": 1, "debug": false, "tag": "cn:androidx.recyclerview.widget.RecyclerView#", "family": [], "descendant": [], "failed": "", "traverseSelf": false, "retryCount": "0", "startIndex": "0", "lastIndex": "0", "randomPickCount": "0", "clickable": false, "className": "", "children": [{ "type": "if", "desc": "条件处理", "class": 1, "debug": false, "target": "item", "family": [1], "descendant": [], "conditions": "className@#android.widget.RelativeLayout@#", "children": [{ "type": "clickAndEnter", "desc": "点击进入页面", "class": "2", "debug": false, "family": [], "descendant": [], "checkTag": "txt:分享#", "mode": "2", "false": { "type": "back2Page", "desc": "返回页面", "debug": false, "tag": "txt:首页#", "root": "", "backFirst": "false", "failed": "", "duration": "500", "maxStep": "5", "beforeWait": "0", "afterWait": "0" }, "failed": "", "duration": "500", "maxStep": "5", "beforeWait": "0", "afterWait": "0", "target": "item", "children": [{ "type": "scroll", "desc": "滚动处理", "class": 1, "debug": false, "direction": "up", "tag": "", "family": [], "descendant": [], "widgetIndex": "0", "minDistance": "0.2", "maxDistance": "0.5", "minScrollCount": "4", "maxScrollCount": "6", "minDuration": "1000", "maxDuration": "3000", "beforeWait": "1000", "afterWait": "1000" }, { "type": "back2Page", "desc": "返回页面", "debug": false, "tag": "txt:首页#", "root": "", "backFirst": "true", "failed": "", "duration": "500", "maxStep": "5", "beforeWait": "0", "afterWait": "0" }] }] }] }, { "type": "scroll", "desc": "滚动处理", "class": 1, "debug": false, "direction": "up", "tag": "", "family": [], "descendant": [], "widgetIndex": "0", "minDistance": "0.98", "maxDistance": "0.98", "minScrollCount": "2", "maxScrollCount": "3", "minDuration": "500", "maxDuration": "500", "beforeWait": "1000", "afterWait": "1000" }] }] }] }], "desc": "根模块", "debug": false } } ``` -------------------------------- ### Start and Stop Audio Recording (JavaScript) Source: https://www.aznfz.com/document/record This snippet demonstrates how to request audio capture permission, start recording audio to a specified file, and then stop the recording. It utilizes functions like requestAudioCapture, startRecordAudio, and stopRecordAudio. The startRecordAudio function accepts a file path and optional recording settings such as sample rate, channel count, and bits per sample. ```javascript function main() { requestAudioCapture(); var r = startRecordAudio('mys2.wav', {sampleRate: 32000}); console.log('', r) sleep(20000); stopRecordAudio(); } ``` -------------------------------- ### Set and Get Radio Button Checked State (JavaScript) Source: https://www.aznfz.com/document/ui_radio Demonstrates how to programmatically set and retrieve the checked state of a radio button using JavaScript. The 'checked' property can be set to true or false, and its current state can be obtained by calling the function without arguments. This functionality is typically used within a UI setup or event handler. ```javascript function main() { setupUI(); // Sets up the UI elements. // Sets the radio button with id 'demo1' to be checked. ui('demo1').checked(true); // Retrieves the checked status of the radio button with id 'demo2'. var checkStatus = ui('demo2').checked(); } ``` ```javascript function main() { setupUI(); } function onUIResume() { // Set the checked state to true. ui('demo').checked(true); // ui('demo').value(true); // Alternative method to set state. // Get the current checked state. console.log('checked:' + ui('demo').checked()); // console.log('checked:' + ui('demo').value()); // Alternative method to get state. } ``` -------------------------------- ### Checkbox Control Introduction and Usage Source: https://www.aznfz.com/document/ui_checkbox Demonstrates the basic setup and event handling for a checkbox control. It shows how to initialize the UI and log the checked state when the checkbox is interacted with. ```javascript function main() { setupUI(); } function cbChecked(checkbox, checked) { console.log('checkbox:' + checkbox.text + ' value:' + checked); } ``` -------------------------------- ### UI Introduction Source: https://www.aznfz.com/document/big_model Provides an overview of the User Interface (UI) system. This section is crucial for understanding how to build and interact with the application's graphical elements. It covers fundamental concepts. -------------------------------- ### UI Template Introduction Source: https://www.aznfz.com/document/ui_template Introduces the concept of UI templates as the root for all UI controls. It details attributes like 'fullscreen', 'with', and 'height' that control the display properties of UI elements. ```javascript function main() { setupUI(); } ``` ```javascript function main() { setupUI(); } ``` ```javascript function main() { setupUI(); } ``` -------------------------------- ### GET Network Request Source: https://www.aznfz.com/document/ui_image Performs a GET request to a specified URL. ```APIDOC ## GET /network/get ### Description Sends a GET request to the specified URL and retrieves the response. ### Method GET ### Endpoint /network/get ### Parameters #### Query Parameters - **url** (string) - Required - The URL to send the GET request to. ### Request Example ```json { "url": "https://example.com/api/data" } ``` ### Response #### Success Response (200) - **response** (string) - The response from the GET request. #### Response Example ```json { "response": "{\"key\": \"value\"}" } ``` ``` -------------------------------- ### Download File with Resume Support Source: https://www.aznfz.com/document/network Downloads a file from a given URL, supporting breakpoint resumes. It returns the full path of the downloaded file. For media files to be accessible in the gallery, an additional update function must be called. The download process triggers system messages for start, progress, success, and failure, which can be handled via the `cbMessage` callback. ```javascript function main() { var filePath = downloadFile('https://downsc.chinaz.net/Files/DownLoad/sound1/202303/y1687.wav', '/sdcard/path', 'b.wav'); console.log('end:', filePath); } // Callback function, automatically called by the system function cbMessage(msgId, p1, p2) { if (msgId == 'msg_download_start') { Toast.show('开始下载中...'); } else if (msgId == 'msg_download_progress') { Toast.show('下载进度:' + p1 + '%'); } else if (msgId == 'msg_download_success') { Toast.show('下载成功'); } else if (msgId == 'msg_download_failed') { Toast.show('下载失败'); } } ``` -------------------------------- ### HTTP GET Request Source: https://www.aznfz.com/document/network Performs an HTTP GET request to a specified URL and returns the result synchronously. ```APIDOC ## GET /httpGet ### Description Performs an HTTP GET request to a specified URL and returns the result synchronously. ### Method GET ### Endpoint `/httpGet` ### Parameters #### Query Parameters - **url** (string) - Required - The target URL. - **headers** (object) - Optional - Request headers. ### Response #### Success Response (200) - **state** (string) - Indicates 'success' or 'failed'. - **data** (string) - The data returned on success, or the error reason on failure. ### Request Example ```javascript var ret = httpGet('https://xxx.com?a=12&b=afb', {Accept: 'text/plain'}); console.log('ret:' + ret); ``` ``` -------------------------------- ### Open App Info Page in JavaScript Source: https://www.aznfz.com/document/global Navigates the user to the application's information page in the system settings. This page allows users to perform actions like stopping or uninstalling the app. It requires the application's package name as a string argument. ```javascript openAppInfoPage('com.libra.aznfz'); ``` -------------------------------- ### randInt Source: https://www.aznfz.com/document/global Generates a random integer within the range [start, end), including start but excluding end. ```APIDOC ## GET /randInt ### Description Generates a random integer within the range [start, end), including start but excluding end. ### Method GET ### Endpoint /randInt ### Parameters #### Query Parameters - **start** (integer) - Required - The starting value of the range. - **end** (integer) - Required - The ending value of the range (exclusive). ### Request Example ```javascript // Generate a random integer between 10 (inclusive) and 50 (exclusive) var ret = randInt(10, 50); console.log('ret:', ret); ``` ### Response #### Success Response (200) - **randomInt** (integer) - The generated random integer. #### Response Example ```json { "randomInt": 25 } ``` ``` -------------------------------- ### Hello World 示例 - 智能构建脚本 Source: https://www.aznfz.com/document/autoBuild 这是一个使用智能构建脚本创建的“Hello World”示例,它演示了如何启动微信应用并滚动屏幕三次。该脚本通过配置元数据来定义应用启动、循环滚动和弹出消息等操作,无需编写传统代码。 ```json { "type": "root", "children": [{ "type": "declareVar", "var": [{ "name": "temp", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "ret", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "view", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "viewContainer", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "item", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "index", "type": "normal", "initType": "null", "initValue": "null" }, { "name": "data", "type": "normal", "initType": "string", "initValue": "" }, { "name": "text", "type": "normal", "initType": "string", "initValue": "" }] }, { "type": "main", "desc": "业务逻辑入口", "debug": false, "params": [], "children": [{ "type": "launchApp", "desc": "启动APP", "debug": false, "packageName": "com.tencent.mm", "tag": "txt:发现|txt:搜索#", "maxStep": "30", "children": [{ "type": "toast", "desc": "弹出框", "debug": false, "textList": ["string-微信启动成功"], "x": "-1", "y": "-1", "duration": "1000", "beforeWait": "0", "afterWait": "0" }, { "type": "loop", "desc": "循环处理", "class": "2", "debug": false, "minCount": "3", "maxCount": "3", "indexVarName": "index", "children": [{ "type": "scroll", "desc": "滚动处理", "class": 1, "debug": false, "direction": "up", "tag": "", "family": [], "descendant": [], "widgetIndex": "0", "minDistance": "0.8", "maxDistance": "0.8", "minScrollCount": "1", "maxScrollCount": "1", "minDuration": "500", "maxDuration": "500", "beforeWait": "1000", "afterWait": "1000" }, { "type": "toast", "desc": "弹出框", "debug": false, "textList": ["string-滚动:", "var-index!-2"], "x": "-1", "y": "-1", "duration": "1000", "beforeWait": "0", "afterWait": "0" }] }, { "type": "toast", "desc": "弹出框", "debug": false, "textList": ["string-结束"], "x": "-1", "y": "-1", "duration": "1000", "beforeWait": "0", "afterWait": "0" }] }] }], "desc": "根模块", "debug": false } ``` -------------------------------- ### GET Network Request Source: https://www.aznfz.com/document/ui_radio Performs a GET request to a specified URL. This is commonly used to retrieve data from a server. ```javascript async function getRequest(url) { const response = await fetch(url); const data = await response.json(); return data; } ``` -------------------------------- ### Start Device API Source: https://www.aznfz.com/document/openApi Initiates an action on one or more devices. This API requires the developer key, access token, and the device UUID(s). It supports an optional `forceRun` parameter to override existing scripts. If multiple UUIDs are provided, they should be URI-encoded. ```HTTP GET /api/device/start?clientKey=YOUR_KEY&accessToken=YOUR_ACCESS_TOKEN&uuids=DEVICE_UUID ``` ```HTTP GET /api/device/start?clientKey=YOUR_KEY&accessToken=YOUR_ACCESS_TOKEN&uuids=%5B%22UUID1%22%2C%22UUID2%22%5D&forceRun=false ``` -------------------------------- ### randFloat Source: https://www.aznfz.com/document/global Generates a random floating-point number within the range [start, end), including start but excluding end. ```APIDOC ## GET /randFloat ### Description Generates a random floating-point number within the range [start, end), including start but excluding end. ### Method GET ### Endpoint /randFloat ### Parameters #### Query Parameters - **start** (float) - Required - The starting value of the range. - **end** (float) - Required - The ending value of the range (exclusive). ### Request Example ```javascript // Generate a random float between 10.0 (inclusive) and 50.0 (exclusive) var ret = randFloat(10.0, 50.0); console.log('ret:', ret); ``` ### Response #### Success Response (200) - **randomFloat** (float) - The generated random floating-point number. #### Response Example ```json { "randomFloat": 35.789 } ``` ```