脚本:
// 检查悬浮窗权限
if (!floaty.checkPermission()) {
// 没有悬浮窗权限,提示用户并跳转请求
toast("本脚本需要悬浮窗权限来显示悬浮窗,若已禁止请在随后的界面中允许并重新运行本脚本。");
floaty.requestPermission();
exit();
} else {
toastLog('已有悬浮窗权限');
}
// 获取设备屏幕的宽度和高度
var screenWidth = device.width;
var screenHeight = device.height;
// 计算中心坐标
var centerX = screenWidth / 2;
var centerY = screenHeight / 2;
// 创建悬浮窗口
var w = floaty.window(
<frame gravity="center">
<vertical>
<button id="start" text="开始"/>
<button id="stop" text="停止"/>
</vertical>
</frame>
);
// 设置窗口大小和初始位置
w.setSize(170, 400);
w.setPosition(0, 500);
w.exitOnClose();
// 给停止按钮添加点击事件
w.stop.setOnClickListener(function() {
// 执行停止操作
toast('停止操作');
exit(); // 退出脚本
});
// 给开始按钮添加点击事件
w.start.setOnClickListener(function() {
// 执行开始操作
toast('开始操作');
// 进行连续点击,这里是点击30次
for(let i = 0; i < 30; i++) {
let rxc1 = centerX + Math.random() * 10 - 5;
let ryc1 = centerY + Math.random() * 10 - 5;
let rxc2 = centerX + Math.random() * 10 - 5;
let ryc2 = centerY + Math.random() * 10 - 5;
click(rxc1, ryc1);
click(rxc2, ryc2);
sleep(500);
}
});
//保持悬浮窗存在
setInterval(() => {}, 1000);
设备信息:
App version: 6.5.7
App version code: 657
Android build version: V12.5.21.0.R
Android release version: 11
Android SDK version: 30
Android build ID: RP1A.200720.011
Device brand: Redmi
Device manufacturer: Xiaomi
Device name: dandelion
Device model: M2006C3LC
Device product name: dandelion
Device hardware name: mt6762
ABIs: [armeabi-v7a, armeabi]
ABIs (32bit): [armeabi-v7a, armeabi]
ABIs (64bit): []
错误信息:
java.lang.IllegalStateException: Fragment ScriptListFragment{2959361} (c8b3c385-d4c4-4fee-9f76-816591b841dc) not attached to a context.
androidx.fragment.app.Fragment.requireContext(Fragment.java:900)
org.autojs.autojs.ui.main.scripts.ScriptListFragment$explorerView$2.invoke(ScriptListFragment.kt:55)
org.autojs.autojs.ui.main.scripts.ScriptListFragment$explorerView$2.invoke(ScriptListFragment.kt:55)
kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
org.autojs.autojs.ui.main.scripts.ScriptListFragment.getExplorerView(ScriptListFragment.kt:55)
org.autojs.autojs.ui.main.MainActivity$onCreate$1$1$1$permission$1.invoke(MainActivity.kt:91)
org.autojs.autojs.ui.main.MainActivity$onCreate$1$1$1$permission$1.invoke(MainActivity.kt:89)
org.autojs.autojs.ui.main.MainActivityKt$rememberExternalStoragePermissionsState$1.invoke(MainActivity.kt:246)
org.autojs.autojs.ui.main.MainActivityKt$rememberExternalStoragePermissionsState$1.invoke(MainActivity.kt:240)
com.google.accompanist.permissions.MutableMultiplePermissionsStateKt$rememberMutableMultiplePermissionsState$launcher$1.invoke(MutableMultiplePermissionsState.kt:61)
com.google.accompanist.permissions.MutableMultiplePermissionsStateKt$rememberMutableMultiplePermissionsState$launcher$1.invoke(MutableMultiplePermissionsState.kt:57)
androidx.activity.compose.ActivityResultRegistryKt$rememberLauncherForActivityResult$1.invoke$lambda-0(ActivityResultRegistry.kt:106)
androidx.activity.compose.ActivityResultRegistryKt$rememberLauncherForActivityResult$1.$r8$lambda$dCDOHypJPJiF_gC4kcw2C1QNWFU(Unknown Source:0)
androidx.activity.compose.ActivityResultRegistryKt$rememberLauncherForActivityResult$1$$ExternalSyntheticLambda0.onActivityResult(Unknown Source:2)
androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:406)
androidx.activity.ComponentActivity$2$1.run(ComponentActivity.java:188)
android.os.Handler.handleCallback(Handler.java:938)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:236)
android.app.ActivityThread.main(ActivityThread.java:7912)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
运行脚本后,按钮正常出现;点击“”停止“后,正常退出;点击“开始”后,过一段时间autox.js停止运行,出现如上报错(将sleep换成setTimeout还是这样)。