如何检测连接的蓝牙外围设备(自拍杆)的单击事件? [英] How to detect click event of connected Bluetooth peripheral device (Selfie stick)?

查看:232
本文介绍了如何检测连接的蓝牙外围设备(自拍杆)的单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经自拍杆连接到我的手机上。我可以用下面code找到设备ID:

I have Selfie stick connected to my phone. I am able to find device ID using below code:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
        this.registerReceiver(mReceiver, filter);
}

  //The BroadcastReceiver that listens for bluetooth broadcasts
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
                //Device is now connected
                Toast.makeText(getApplicationContext(), "ACTION_ACL_CONNECTED" + device, Toast.LENGTH_LONG).show();
            }
         }
    };

我的问题是我怎么可以检测到这种连接外围设备的按钮preSS / click事件?

My question is how I can detect button press/click event of this connected peripheral device?

帮助中的code段/补习/评论的形式是非常AP preciable。
谢谢!!!

Help in form of code snippet/tutorial/comments is highly appreciable. Thanks!!!

编辑:

当我自拍杆音量+键preSS按钮监听事件

When I press button of Selfie stick Volume + button listen to the event

推荐答案

我找到了答案。这是非常简单的。只是覆盖活动的onkeydown()方法。

I found the answer. It was very simple. Just override onKeyDown() method of Activity.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    return super.onKeyDown(keyCode, event);
}

下面键code 是事件的名称返回。

Here keyCode is the event name returned.

这篇关于如何检测连接的蓝牙外围设备(自拍杆)的单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆