2022年2月10日 星期四

Android Studio - BluetoothDevice Classes(藍牙設備類)(三十六)

Android Studio - BluetoothDevice Classes(藍牙設備類)(三十六):

Android 的本地設備 BluetoothDevice(藍牙設備)的類。BluetoothDevice 類實際上只是一個藍牙硬體位址的簡單包裝,可創建與相應設備的連接或查詢其相關資訊,例如名稱,位址,類別和綁定狀態。這個類上的操作會使用這個用來創建 BluetoothDevice 類的 BluetoothAdapter 類執行在遠端藍牙硬體上。為了獲得 BluetoothDevice 類,使用 BluetoothAdapter.getRemoteDevice(String)方法去創建一個表示 已知 MAC 位址的設備(使用者可以通過帶有 BluetoothAdapter 類來完成對設備的查找)或者從一個通過 BluetoothAdapter.getBondedDevices() 得到返回值的有聯繫的設備集合來得到該設備。

Android Studio BluetoothDevice Classes(藍牙設備類)
BluetoothDevice Classes:

Class屬性

參數

描述

ACTION_ACL_CONNECTED

String

Broadcast Action: Indicates a low level (ACL) connection has been established with a remote device

ACTION_ACL_DISCONNECTED

String

Broadcast Action: Indicates a low level (ACL) disconnection from a remote device

ACTION_ACL_DISCONNECT_REQUESTED

String

Broadcast Action: Indicates that a low level (ACL) disconnection has been requested for a remote deviceand it will soon be disconnected

ACTION_ALIAS_CHANGED

String

Broadcast Action: Indicates the alias of a remote device has been changed

ACTION_BOND_STATE_CHANGED

String

Broadcast Action: Indicates a change in the bond state of a remote device

ACTION_CLASS_CHANGED

String

Broadcast Action: Bluetooth class of a remote device has changed

ACTION_FOUND

String

Broadcast Action: Remote device discovered

ACTION_NAME_CHANGED

String

Broadcast Action: Indicates the friendly name of a remote device has been retrieved for the first timeor changed since the last retrieval

ACTION_PAIRING_REQUEST

String

Broadcast Action: This intent is used to broadcast PAIRING REQUEST

For apps targeting BuildVERSION_CODES#R or lowerthis requires the Manifestpermission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag

ACTION_UUID

String

Broadcast Action: This intent is used to broadcast the UUID wrapped as a ParcelUuid of the remote device after it has been fetched

ADDRESS_TYPE_PUBLIC

int

Hardware MAC Address of the device

ADDRESS_TYPE_RANDOM

int

Address is either resolvablenon-resolvable or static

BOND_BONDED

int

Indicates the remote device is bonded (paired)

BOND_BONDING

Int

Indicates bonding (pairing) is in progress with the remote device

BOND_NONE

Int

Indicates the remote device is not bonded (paired)

DEVICE_TYPE_CLASSIC

Int

Bluetooth device typeClassic - BR/EDR devices

DEVICE_TYPE_DUAL

Int

Bluetooth device typeDual Mode - BR/EDR/LE

DEVICE_TYPE_LE

Int

Bluetooth device typeLow Energy - LE-only

DEVICE_TYPE_UNKNOWN

Int

Bluetooth device typeUnknown

ERROR

Int

Sentinel error value for this class

EXTRA_BOND_STATE

String

Used as an int extra field in ACTION_BOND_STATE_CHANGED intents

EXTRA_CLASS

String

Used as a Parcelable BluetoothClass extra field in ACTION_FOUND and ACTION_CLASS_CHANGED intents

EXTRA_DEVICE

String

Used as a Parcelable BluetoothDevice extra field in every intent broadcast by this class

EXTRA_NAME

String

Used as a String extra field in ACTION_NAME_CHANGED and ACTION_FOUND intents

EXTRA_PAIRING_KEY

String

Used as an int extra field in ACTION_PAIRING_REQUEST intents as the value of passkey

EXTRA_PAIRING_VARIANT

String

Used as an int extra field in ACTION_PAIRING_REQUEST intents to indicate pairing method used

EXTRA_PREVIOUS_BOND_STATE

String

Used as an int extra field in ACTION_BOND_STATE_CHANGED intents

EXTRA_RSSI

String

Used as an optional short extra field in ACTION_FOUND intents

EXTRA_UUID

String

Used as an extra field in ACTION_UUID intentsContains the ParcelUuids of the remote device which is a parcelable version of UUID

PAIRING_VARIANT_PASSKEY_CONFIRMATION

int

The user will be prompted to confirm the passkey displayed on the screen or an app will confirm the passkey for the user

PAIRING_VARIANT_PIN

int

The user will be prompted to enter a pin or an app will enter a pin for user

PHY_LE_1M

int

Bluetooth LE 1M PHY

PHY_LE_1M_MASK

int

Bluetooth LE 1M PHY mask

PHY_LE_2M

int

Bluetooth LE 2M PHY

PHY_LE_2M_MASK

int

Bluetooth LE 2M PHY mask

PHY_LE_CODED

int

Bluetooth LE Coded PHY

PHY_LE_CODED_MASK

int

Bluetooth LE Coded PHY mask

PHY_OPTION_NO_PREFERRED

int

No preferred coding when transmitting on the LE Coded PHY

PHY_OPTION_S2

int

Prefer the S=2 coding to be used when transmitting on the LE Coded PHY

PHY_OPTION_S8

int

Prefer the S=8 coding to be used when transmitting on the LE Coded PHY

TRANSPORT_AUTO

int

No preference of physical transport for GATT connections to remote dual-mode devices

TRANSPORT_BREDR

int

Prefer BR/EDR transport for GATT connections to remote dual-mode devices

TRANSPORT_LE

int

Prefer LE transport for GATT connections to remote dual-mode devices


BluetoothDevice Public Classes:

Class 屬性

參數

描述

createBond()

boolean

Start the bonding (pairing) process with the remote device

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

fetchUuidsWithSdp()

boolean

Perform a service discovery on the remote device to get the UUIDs supported

getAlias()

String

Get the locally modifiable name (alias) of the remote Bluetooth device

getBluetoothClass()

BluetoothClass

Get the Bluetooth class of the remote device

getBondState()

int

Get the bond state of the remote device

getName()

String

Get the friendly Bluetooth name of the remote device

getType()

int

Get the Bluetooth device type of the remote device

getUuids()

ParcelUuid[]

Returns the supported features (UUIDs) of the remote device

hashCode()

int

Returns a hash code value for the object

setAlias(String alias)

int

Sets the locally modifiable name (alias) of the remote Bluetooth device

setPairingConfirmation(boolean confirm)

boolean

Confirm passkey for PAIRING_VARIANT_PASSKEY_CONFIRMATION pairing

setPin(byte[] pin)

boolean

Set the pin during pairing when the pairing method is PAIRING_VARIANT_PIN

For apps targeting BuildVERSION_CODES#R or lowerthis requires the Manifestpermission#BLUETOOTH_ADMIN permission which can be gained with a simple <uses-permission> manifest tag

toString()

String

Returns a string representation of this BluetoothDevice

writeToParcel(Parcel out, int flags)

void

Flatten this object in to a Parcel


BluetoothDevice Classes:

Class 屬性

描述

BluetoothGatt

connectGatt(Context context,boolean autoConnect,BluetoothGattCallback callback)

Connect to GATT Server hosted by this device

BluetoothGatt

connectGatt(Context context,boolean autoConnect,BluetoothGattCallback callback,int transport,int phy,Handler handler)

Connect to GATT Server hosted by this device

BluetoothGatt

connectGatt(Context context,boolean autoConnect,BluetoothGattCallback callback,int transport,int phy)

Connect to GATT Server hosted by this device

BluetoothGatt

connectGatt(Context context,boolean autoConnect,BluetoothGattCallback callback, int transport)

Connect to GATT Server hosted by this device

BluetoothSocket

createInsecureL2capChannel(int psm)

Create a Bluetooth L2CAP Connection-oriented Channel (CoC) BluetoothSocket that can be used to start a secure outgoing connection to the remote device with the same dynamic protocol/service multiplexer (PSM) value

BluetoothSocket

createInsecureRfcommSocketToServiceRecord(UUID uuid)

Create an RFCOMM BluetoothSocket socket ready to start an insecure outgoing connection to this remote device using SDP lookup of uuid

BluetoothSocket

createL2capChannel(int psm)

Create a Bluetooth L2CAP Connection-oriented Channel (CoC) BluetoothSocket that can be used to start a secure outgoing connection to the remote device with the same dynamic protocol/service multiplexer (PSM) value

BluetoothSocket

createRfcommSocketToServiceRecord(UUID uuid)

Create an RFCOMM BluetoothSocket ready to start a secure outgoing connection to this remote device using SDP lookup of uuid


發現藍牙設備範例:

if (BluetoothDevice.ACTION_FOUND.equals(action)) {

// Get the BluetoothDevice object from the Intent

BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

// Add the name and address to an array adapter to show in a ListView

mArrayAdapter.add(device.getName()   "\n"   device.getAddress());

}


參考網址:
※ BluetoothDevice

2022年 2月 10日(Thu)天氣報告
氣溫:45.0°F / 7.0°C @ 07:00
風速:每小時 3公里
降雨機會:5%
相對濕度:百分之 98%
天氣:霧

沒有留言:

張貼留言