native.js 监听不到ACTION_MEDIA_BUTTON消息,用离线编译,注册消息是否可以解决?哪位大神帮忙答疑,或者帮忙试试(没用用过AS)
<receiver android:name="io.dcloud.feature.internal.reflect.BroadcastReceiver">
<intent-filter >
<action android:name="android.intent.action.MEDIA_BUTTON"></action>
</intent-filter>
</receiver>
下面是参考锁屏的示例改的,其他消息可以接收到,但是ACTION_MEDIA_BUTTON的消息接收不到。
================================================
var main = plus.android.runtimeMainActivity(); //获取activity
var Intent = plus.android.importClass('android.content.Intent');
var KeyEvent = plus.android.importClass('android.view.KeyEvent');
var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: function(context, intent) {
//实现onReceiver回调函数
console.log('2222222222222222');
var event = new KeyEvent(intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT));
Actions.push(intent.getAction())
Keys.push(event.getKeyCode())
console.log(event.getKeyCode());
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('解锁');
}
// main.unregisterReceiver(receiver);
}
});
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
var filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_BUTTON);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
main.registerReceiver(receiver, filter); //注册监听
}
1 个回复
追影和糖糖
关注