问题描述
是蓝牙耳机还是手机?
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.
-
我引用了示例和代码,因为它们建议我仅配对/取消配对蓝牙设备. Android:如何以编程方式配对蓝牙设备?
I referred the examples and codes in that they suggest me topair/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 ofdevice 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:
因此,在允许用户选择要连接的设备或过滤显示的BluetoothDevice
列表之前,请尝试查看BluetoothClass
是否具有正确的设备类型.
So before you allow the user to select the device to connect to, or to filter the list of BluetoothDevice
s 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中已连接的蓝牙设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!