写一个监听手机飞行模式开关的例子。
var receiver;
main = plus.android.runtimeMainActivity(); //获取activity
receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: function(context, intent) { //实现onReceiver回调函数
plus.android.importClass(intent);
console.log(intent.getAction());
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_AIRPLANE_MODE_CHANGED); //监听飞行模式
main.registerReceiver(receiver, filter); //注册监听
翻皮的鱼
我也想要这个
2019-08-17 17:00