广播模块代码在autojs4.1.1版本运行正常,但在pro7.0版本上运行报错(未解决)

使用版本:Auto.js7.0.4.1 autojsprov7.0.4.1vip版本-Android文档类资源-CSDN下载

目录

广播注册报错

代码示例

报错日志

查看文档发现原因:Auto.js Pro Docs

总结


广播注册报错

代码示例

注册的是Intent.ACTION_TIME_TICK广播。

//广播接收者回调
function initReceiver(){
        let receiver = new JavaAdapter(android.content.BroadcastReceiver, {
            onReceive: function (context, intent) {
              let b = false;
              log(intent);
              switch (intent.action) {
                case Intent.ACTION_TIME_TICK:
                    if(!b){
                        b = true;
                        setTimeout(function(){
                            // toastLog("系统的时间:" + myUtils.currentFormatDate());
                            b = false;
                            if(wxAutoConfigObj.openState&&wxAutoConfigObj.timingTime === myUtils.getCurrentTime()){
                                try{
                                    if(!myUtils.isEmpty(wxAutoConfigObj.curGroupName) && textContains(wxAutoConfigObj.curGroupName).findOne(3000)){
                                        getServiceInfo(); //广播推送
                                    }
                                }catch(err){
                                    toastLog("定时执行消息报错:\n" + err);
                                }
                            }
                            if(exeRestartState){
                                if(exeRestartTime === myUtils.getCurrentTime()){
                                    threads.start(function(){
                                        toast("3秒后重启设备");
                                        sleep(3000);
                                        shell("reboot", true);
                                    })
                                }
                            }
                        }, 3000);
                    }
                    break;
            }
        });
}

//实例化广播接收者类 
initReceiver();
//注册广播
registerReceiver();

报错日志

Attempt to write to field 'int c.m.b.e.a$b.b' on a null object reference

java.lang.NullPointerException: Attempt to write to field 'int c.m.b.e.a$b.b' on a null object reference

查看文档发现原因:Auto.js Pro Docs

感情是有bug,真坑

总结

目前无法解决这个问题,除非auto升级到Pro 8.0才行,或是降低版本到4.1也是可以的。能解决的大神麻烦在留言区讨论。

猜你喜欢

转载自blog.csdn.net/piyangbo/article/details/125496842