beg*_*ner 8 android bluetooth android-broadcast android-bluetooth
无论是蓝牙耳机还是手机?
如何在Android代码中区分蓝牙耳机和支持蓝牙的Android设备.
我正在开发一个小应用程序,因为我有通过蓝牙阻止数据传输的功能,但它需要允许通过蓝牙耳机进行通信.
我提到了示例和代码,因为他们建议我只配对/取消配对蓝牙设备. Android:如何以编程方式配对蓝牙设备?
or else
Run Code Online (Sandbox Code Playgroud)获取所有连接的设备. 在Android中,如何获取连接的蓝牙设备的配置文件?
是否可以在与设备连接类型相关的设备中获取任何广播消息?
请帮我解决这个问题,将连接的蓝牙设备区分为耳机/安卓设备(手机)等.,
先感谢您.
一旦你扫描并找到一个BluetoothDevice调用方法BluetoothDevice.getBluetoothClass().这将返回一个BluetoothClass对象,文档说明如下:
表示蓝牙类,描述设备的一般特征和功能.例如,蓝牙类将指定一般设备类型,例如电话,计算机或耳机,以及它是否能够提供诸如音频或电话之类的服务.
因此,在允许用户选择要连接的设备或过滤显示的列表之前BluetoothDevice,请尝试查看是否BluetoothClass具有正确的设备类型.
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.
}
Run Code Online (Sandbox Code Playgroud)
如果您希望进一步区分设备类,可以在此处找到不同的设备类常量.
| 归档时间: |
|
| 查看次数: |
2806 次 |
| 最近记录: |