2022年2月11日 星期五

Android Studio - BluetoothClass(藍牙類)(三十七)

Android Studio - BluetoothClass(藍牙類)(三十七):

BluetoothClass(藍牙類)可用作粗略描述設備的提示(例如,在 UI 中顯示圖標),但不能可靠地描述設備實際支持的藍牙配置文件或服務,例如一個藍牙類會指定如電話、電腦或耳機的通用設備類型,可以提供皆如音訊或者電話的服務。每個藍牙類都是有 0個或更多的服務類,以及一個設備類組成。設備類將被分解成主要和較小的設備類部分。當運用 createRfcommSocketToServiceRecord(UUID) 和 listenUsingRfcommWithServiceRecord(String, UUID) 來創建 RFCOMM 埠的時候,SDP 請求就會自動執行。

Android Studio BluetoothClass(藍牙類)
BluetoothClass:

Class屬性

參數

描述

BluetoothClass.Device

 

Defines all device class constants

BluetoothClass.Service

 

Defines all service class constants


BluetoothDevice Public Methods:

Class屬性

參數

描述

describeContents()

int

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation

equals(Object o)

boolean

Indicates whether some other object is "equal to" this one

getDeviceClass()

int

Return the (major and minor) device class component of this BluetoothClass

getMajorDeviceClass()

int

Return the major device class component of this BluetoothClass

hasService(int service)

boolean

Return true if the specified service class is supported by this BluetoothClass

hashCode()

int

Returns a hash code value for the object

toString()

String

Returns a string representation of the object

writeToParcel(Parcel out, int flags)

void

Flatten this object in to a Parcel


偵測藍牙設備類型:

BluetoothClass bluetoothClass = device.getBluetoothClass();

   switch (bluetoothClass.getMajorDeviceClass()) {

     case BluetoothClass.Device.Major.PERIPHERAL:

       switch (bluetoothClass.getDeviceClass() & 0x05C0) {

         case 0x0540: // Keyboard - 1314

           break;

         case 0x05C0: // Keyboard + mouse combo.

           break;

         case 0x0580: // Mouse - 1408

           break;

         default: // Other.

           break;

       }

   }


參考網址:
※ BluetoothClass

2022年 2月 11日(Fri)天氣報告
氣溫:45.0°F / 7.0°C @ 07:00
風速:每小時 13公里
降雨機會:4%
相對濕度:百分之 83%
天氣:多雲

沒有留言:

張貼留言