回答
// 文档地址 https://docs.hamibot.com/
// 在任务页开启监控截屏权限线程的示例代码
threads.start(function () {
const check = () => {
let activity = currentActivity().toLowerCase();
// 适配MIUI系统
if (activity.indexOf('permission') !== -1) {
if (id('com.android.systemui:id/dialog_title')
.textContains('Hamibot').exists()) {
id('android:id/button1').findOnce().click();
return;
}
}
// 华为EMUI适配示例
if (id('android:id/alertTitle').textContains('屏幕截图').exists()) {
click('允许');
return;
}
// OPPO ColorOS适配示例
if (textMatches(/屏幕录制/).exists()) {
click('立即开始');
return;
}
// 500ms循环检测
setTimeout(check, 500);
};
check();
});
// 请求截图权限
if (!requestScreenCapture()) {
toastLog('需要开启截图权限');
hamibot.exit();
}
// 退出监控线程(执行完主流程后)
threads.shutDownAll();
sleep(1000); // 等待权限弹窗消失
ℹ️ 本回答由 AI 生成,内容仅供参考