Native.JS监听手机锁屏,解锁,开屏

var receiver;
mui.plusReady(function() {
main = plus.android.runtimeMainActivity(); //获取activity
// 广播接收
var ALARM_RECEIVER = "alarm_receiver";
receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: function(context, intent) { //实现onReceiver回调函数
var Intent = plus.android.importClass('android.content.Intent');
console.log(intent.getAction());
//action = intent.getAction();
if(intent.getAction() == Intent.ACTION_SCREEN_ON) {
console.log('开屏')
} else if(intent.getAction() == Intent.ACTION_SCREEN_OFF) {
console.log('锁屏')
} else if(intent.getAction() == Intent.ACTION_USER_PRESENT) {
console.log('解锁')
}
result.textContent += '\nAction :' + intent.getAction();
main.unregisterReceiver(receiver);
}
});
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
var Intent = plus.android.importClass('android.content.Intent');
var filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
main.registerReceiver(receiver, filter); //注册监听
})

代码已测试过了ctrl+c直接使用

回答

以上是Native.JS监听手机锁屏,解锁,开屏的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>