kang7979 发布的帖子
红米K40升级HyperOS后,读取短信的脚本不工作了。另外我发现启动应用的脚本也不能用了。autoxjs的版本是6.5.8,重装并重新设置权限也无济于事。这段代码在以前MIUI上是正常工作的。
请教大家有没有类似情况,如何解决?
"ui"
importPackage(android.content);
importClass(android.telephony.SmsMessage);
var filter=new IntentFilter();
filter.addAction("android.provider.Telephony.SMS_RECEIVED");
var receiver = new JavaAdapter(android.content.BroadcastReceiver, {
onReceive : function(context, intent) {
var sender = null;
var bundle = intent.getExtras();
var format = intent.getStringExtra("format");
if (bundle != null) {
var pdus = bundle.get("pdus");
for (object in pdus) {
var message=SmsMessage.createFromPdu(pdus[object],format);
sender = message.getOriginatingAddress();
messageBody = (message.getMessageBody());
log("短信内容: " + messageBody);
}
}
});
context.registerReceiver(receiver,filter);
setInterval(()=>{},1000);
events.on("exit", function () {
context.unregisterReceiver(receiver);
})