如何判断蓝牙设备类型
生活随笔
收集整理的這篇文章主要介紹了
如何判断蓝牙设备类型
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
我們在開發(fā)Android的藍(lán)牙應(yīng)用時,可能需要知道掃描到的藍(lán)牙設(shè)備是什么類型,然后過濾掉不符合要求的設(shè)備,只保留符合要求的設(shè)備,例如我們在車載系統(tǒng)上開發(fā)藍(lán)牙電話應(yīng)用時,我們希望只顯示手機(jī)藍(lán)牙設(shè)備,那么如何從搜索到的藍(lán)牙設(shè)備中選擇出手機(jī)藍(lán)牙設(shè)備?
其實(shí)Android已經(jīng)為我們提供了相應(yīng)的API來識別設(shè)備類型,假如你已經(jīng)獲取到了藍(lán)牙設(shè)備,設(shè)備對象為device:
那么可以通過下面的方法獲取設(shè)備類型->
BluetoothClass bluetoothClass = device.getBluetoothClass(); final int deviceClass = bluetoothClass.getDeviceClass(); //設(shè)備類型(音頻、手機(jī)、電腦、音箱等等) final int majorDeviceClass = bluetoothClass.getMajorDeviceClass();//具體的設(shè)備類型(例如音頻設(shè)備又分為音箱、耳機(jī)、麥克風(fēng)等等)然后這樣判斷
if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) {//音箱} else if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_MICROPHONE) {//麥克風(fēng)} else if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES) {//耳機(jī)} else if (majorDeviceClass == BluetoothClass.Device.Major.COMPUTER) {//電腦} else if (majorDeviceClass == BluetoothClass.Device.Major.PHONE) {//手機(jī)} else if (majorDeviceClass == BluetoothClass.Device.Major.HEALTH) {//健康類設(shè)備} else {//其它藍(lán)牙設(shè)備}下面是我總結(jié)了一下藍(lán)牙設(shè)備的類型:
| 設(shè)備類型 | deviceClass [十六進(jìn)制] | deviceClass [十進(jìn)制] | majorDeviceClass |
| 電腦 | 0x0100 | 256 | 公司電腦(260) |
| 手機(jī) | 0x0200 | 512 | 華為手機(jī) |
| 音箱 | 0x0400 | 1024 | 華為耳機(jī)/米兔音箱(1028)/SANSUI A38S(1028) |
?
本文參考資料:https://blog.csdn.net/weixin_34242819/article/details/92023989
總結(jié)
以上是生活随笔為你收集整理的如何判断蓝牙设备类型的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信智能排号系统,哈林电子会员卡软件 微
- 下一篇: 还在为 520 发愁吗?教你用 Pyth