cnbany
cnbany
  • 发布:2020-03-30 15:31
  • 更新:2020-03-31 13:54
  • 阅读:684

能不能接收到ACTION_MEDIA_BUTTON消息,有离线编译环境的帮忙试试

分类:Native.js

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); //注册监听  
    }  
2020-03-30 15:31 负责人:无 分享
已邀请:
追影和糖糖

该问题目前已经被锁定, 无法添加新回复