如何以编程方式区分android中已连接的蓝牙设备? [英] How to differentiate the connected bluetooth device in android programmatically?

查看:516
本文介绍了如何以编程方式区分android中已连接的蓝牙设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是蓝牙耳机还是手机?

Whether it is a bluetooth headset or mobile phones?

如何在android代码中区分蓝牙耳机和启用了蓝牙的android设备.

how to differentiate the bluetooth headset and bluetooth enabled android device in android code.

我正在开发一个小型应用程序,因为我具有阻止通过蓝牙进行数据传输的功能,但是它需要允许通过蓝牙耳机进行通信.

I am developing a small application,in that I have a feature of blocking the data transfer via bluetooth but it need to allow communication via bluetooth headset.

  • I referred the examples and codes in that they suggest me to pair/unpair the bluetooth devices only. Android: How to pair bluetooth devices programmatically?

                         or else

  • 获取所有已连接的设备. 在Android中,如何获取配置文件连接的蓝牙设备?

  • get all connected devices. In Android, how to get the profile of a connected bluetooth device?

    我是否可以在设备中获得与以下类型有关的广播消息: 设备连接?

    Whether can i get any broadcast message in device related to type of device connection?

    请帮助我将所连接的蓝牙设备区分为耳机/android设备(手机)等.

    Please help me on this to differentiate the connected bluetooth device as headset /android devices(mobile phone).etc.,

    谢谢.

    推荐答案

    扫描并找到BluetoothDevice后,调用方法BluetoothDevice.getBluetoothClass().这将返回一个BluetoothClass对象,并且文档指出以下内容:

    Once you scan and find a BluetoothDevice call the method BluetoothDevice.getBluetoothClass(). This will return a BluetoothClass object and the documentation states the following:

    代表一个蓝牙类,它描述了一般特性 和设备的功能.例如,蓝牙课程将 指定常规设备类型,例如电话,计算机或 耳机,以及它是否能够提供音频或音频等服务 电话.

    Represents a Bluetooth class, which describes general characteristics and capabilities of a device. For example, a Bluetooth class will specify the general device type such as a phone, a computer, or headset, and whether it's capable of services such as audio or telephony.

    因此,在允许用户选择要连接的设备或过滤显示的BluetoothDevice列表之前,请尝试查看BluetoothClass是否具有正确的设备类型.

    So before you allow the user to select the device to connect to, or to filter the list of BluetoothDevices shown, try seeing if the BluetoothClass has the correct device type.

    BluetoothClass bluetoothClass = bluetoothDevice.getBluetoothClass();
    if(bluetoothClass.getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES) {
        // allow user to select this device. I'm not sure exactly which type
        // headphones will be but this is a good guess. You can connect to
        // your Bluetooth headset to find out for sure.
    }
    

    可以在此处找到不同的设备类常量.进一步根据设备类别.

    The different device class constants can be found here in case you want to differentiate by device class further.

    这篇关于如何以编程方式区分android中已连接的蓝牙设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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