[JavaScript] 纯文本查看 复制代码 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); //zc监听
})
|