說明
chrome.bluetoothLowEnergy
API 可用來透過通用屬性設定檔 (GATT) 與 Bluetooth Smart (低功耗) 裝置通訊。
資訊清單
類型
Advertisement
屬性
-
manufacturerData
ManufacturerData[] 選填
廣告資料「製造商專屬資料」欄位中應包含的製造商專屬資料清單。
-
serviceData
ServiceData[] 選填
要納入廣告資料「服務資料」欄位的服務資料清單。
-
serviceUuids
字串陣列 選用
要納入「廣告資料」的「服務 UUID」欄位中的 UUID 清單。這些 UUID 可以是 16 位元、32 位元或 128 位元格式。
-
solicitUuids
字串陣列 選用
要納入廣告資料「徵求 UUID」欄位的 UUID 清單。這些 UUID 可以是 16 位元、32 位元或 128 位元格式。
-
廣告類型。
AdvertisementType
廣告類型。如果選擇「broadcast」,傳送的廣告類型會是 ADV_NONCONN_IND,裝置會以隨機 MAC 位址廣播。如果設為「peripheral」,廣告類型會是 ADV_IND 或 ADV_SCAN_IND,裝置會使用實際的藍牙介面卡 MAC 位址進行廣播。
列舉
「broadcast」
「peripheral」
Characteristic
屬性
-
instanceId
字串 選填
傳回指派給這項特徵的 ID。使用執行個體 ID 區分來自相同 UUID 周邊裝置的特徵,並發出函式呼叫,接收特徵識別碼。如果這個執行個體代表遠端特徵,則為必要欄位。
-
這項特徵的屬性。
-
服務
服務 (選填)
這個特徵所屬的 GATT 服務。
-
uuid
字串
特徵的 UUID,例如 00002a37-0000-1000-8000-00805f9b34fb。
-
值
ArrayBuffer 選填
目前快取的特徵值。透過通知或指標讀取或更新特徵的值時,這個值就會更新。
CharacteristicProperty
代表特徵可能屬性的值。系統會根據這些屬性推斷特徵權限。請參閱藍牙 4.x 規格,瞭解各個屬性的意義。
列舉
「broadcast」
「read」
「writeWithoutResponse」
「write」
「notify」
「indicate」
「authenticatedSignedWrites」
「extendedProperties」
「reliableWrite」
「writableAuxiliaries」
「encryptRead」
「encryptWrite」
「encryptAuthenticatedRead」
「encryptAuthenticatedWrite」
ConnectProperties
屬性
-
永久
布林值
這個旗標表示應用程式的事件頁面卸載時,是否仍保持與裝置的連線 (請參閱「管理應用程式生命週期」)。預設值為
false.
Descriptor
屬性
-
特徵
特性 (選填)
這個描述元所屬的 GATT 特徵。
-
instanceId
字串 選填
傳回指派給這個描述元的 ID。使用執行個體 ID 區分來自具有相同 UUID 的周邊裝置的描述元,並發出會接收描述元 ID 的函式呼叫。如果這個執行個體代表遠端特徵,則為必要欄位。
-
權限Chrome 52 以上版本
這個描述元的權限。
-
uuid
字串
特徵描述元的 UUID,例如 00002902-0000-1000-8000-00805f9b34fb。
-
值
ArrayBuffer 選填
目前快取的描述元值。讀取描述元的值時,這個值會更新。
DescriptorPermission
代表描述元可能權限的值。請參閱藍牙 4.x 規格,瞭解各項權限的意義。
列舉
「read」
「write」
「encryptedRead」
「encryptedWrite」
「encryptedAuthenticatedRead」
「encryptedAuthenticatedWrite」
Device
屬性
-
地址
字串
裝置的位址,格式為「XX:XX:XX:XX:XX:XX」。
-
deviceClass
號碼 選填
裝置類別,是由 http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband 定義的位元欄位。
-
名稱
字串 選填
裝置的人類可讀名稱。
ManufacturerData
屬性
-
資料
number[]
-
id
數字
Notification
屬性
-
shouldIndicate
布林值 選填
選用旗標,可傳送指標而非通知。
-
值
ArrayBuffer
特徵的新值。
NotificationProperties
屬性
-
永久
布林值
這個旗標表示應用程式卸載時,是否應接收通知 (請參閱「管理應用程式生命週期」)。預設值為
false
。
Request
屬性
-
裝置
傳送這項要求的裝置。
-
requestId
數字
這項要求的專屬 ID。回覆這項要求時,請使用這個 ID。
-
值
ArrayBuffer 選填
要寫入的值 (如果是寫入要求)。
Response
屬性
-
isError
布林值
如果是錯誤回應,這個值應為 true。
-
requestId
數字
這是回應的要求 ID。
-
值
ArrayBuffer 選填
回覆值。寫入要求和錯誤回應會忽略這個參數。
Service
屬性
-
deviceAddress
字串 選填
GATT 服務所屬遠端周邊裝置的裝置位址。如果這個執行個體代表遠端服務,則為必填欄位。
-
instanceId
字串 選填
傳回指派給這項服務的 ID。使用執行個體 ID 區分來自具有相同 UUID 的周邊裝置的服務,並發出會接收服務 ID 的函式呼叫。如果這個執行個體代表遠端服務,則為必填欄位。
-
isPrimary
布林值
指出這項服務的類型是主要還是次要。
-
uuid
字串
服務的 UUID,例如 0000180d-0000-1000-8000-00805f9b34fb。
ServiceData
屬性
-
資料
number[]
-
uuid
字串
方法
connect()
chrome.bluetoothLowEnergy.connect(
deviceAddress: string,
properties?: ConnectProperties,
callback?: function,
): Promise<void>
在應用程式和指定位址的裝置之間建立連線。裝置可能已連線並提供 GATT 服務,但未呼叫 connect
。不過,如果應用程式想存取裝置的 GATT 服務,就應呼叫這個函式,確保裝置連線維持不中斷。如果裝置未連線,成功呼叫 connect
後,系統會探索裝置的所有 GATT 服務。
參數
-
deviceAddress
字串
應開啟 GATT 連線的遠端裝置藍牙位址。
-
資源
連線屬性 (選用)。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
createCharacteristic()
chrome.bluetoothLowEnergy.createCharacteristic(
characteristic: Characteristic,
serviceId: string,
callback?: function,
): Promise<string>
建立本機代管的 GATT 特徵。這項特徵必須託管在有效的服務下。如果服務 ID 無效,系統會設定 lastError。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
特徵
要建立的特徵。
-
serviceId
字串
要為其建立特徵的服務 ID。
-
callback
函式 選用
callback
參數如下:(characteristicId: string) => void
-
characteristicId
字串
-
傳回
-
Promise<string>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
createDescriptor()
chrome.bluetoothLowEnergy.createDescriptor(
descriptor: Descriptor,
characteristicId: string,
callback?: function,
): Promise<string>
建立本機代管的 GATT 描述元。這個描述元必須託管在有效的特徵底下。如果特徵 ID 無效,系統會設定 lastError。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
描述元
要建立的描述元。
-
characteristicId
字串
要為其建立這個描述元的特徵 ID。
-
callback
函式 選用
callback
參數如下:(descriptorId: string) => void
-
descriptorId
字串
-
傳回
-
Promise<string>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
createService()
chrome.bluetoothLowEnergy.createService(
service: Service,
callback?: function,
): Promise<string>
建立本機代管的 GATT 服務。這項服務可註冊在區域 GATT 伺服器上提供。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
服務
要建立的服務。
-
callback
函式 選用
callback
參數如下:(serviceId: string) => void
-
serviceId
字串
-
傳回
-
Promise<string>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
disconnect()
chrome.bluetoothLowEnergy.disconnect(
deviceAddress: string,
callback?: function,
): Promise<void>
關閉應用程式與指定位址裝置的連線。請注意,由於可能有其他應用程式開啟連線,這不一定會破壞實體連結本身。
參數
-
deviceAddress
字串
遠端裝置的藍牙位址。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
getCharacteristic()
chrome.bluetoothLowEnergy.getCharacteristic(
characteristicId: string,
callback?: function,
): Promise<Characteristic>
取得屬於指定 GATT 服務且具有指定執行個體 ID 的 GATT 特徵 (如有)。
參數
-
characteristicId
字串
所要求 GATT 特徵的執行個體 ID。
-
callback
函式 選用
callback
參數如下:(result: Characteristic) => void
-
結果
-
傳回
-
Promise<Characteristic>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
getCharacteristics()
chrome.bluetoothLowEnergy.getCharacteristics(
serviceId: string,
callback?: function,
): Promise<Characteristic[]>
取得屬於指定服務的所有已探索 GATT 特徵清單。
參數
-
serviceId
字串
GATT 服務的執行個體 ID,系統應傳回該服務的特徵。
-
callback
函式 選用
callback
參數如下:(result: Characteristic[]) => void
-
結果
特性[]
-
傳回
-
Promise<Characteristic[]>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
getDescriptor()
chrome.bluetoothLowEnergy.getDescriptor(
descriptorId: string,
callback?: function,
): Promise<Descriptor>
取得具有指定執行個體 ID 的 GATT 特徵描述元。
參數
-
descriptorId
字串
所要求 GATT 特徵描述元的執行個體 ID。
-
callback
函式 選用
callback
參數如下:(result: Descriptor) => void
-
結果
-
傳回
-
Promise<Descriptor>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
getDescriptors()
chrome.bluetoothLowEnergy.getDescriptors(
characteristicId: string,
callback?: function,
): Promise<Descriptor[]>
取得屬於指定特徵的 GATT 特徵描述元清單。
參數
-
characteristicId
字串
要傳回描述元的 GATT 特徵的執行個體 ID。
-
callback
函式 選用
callback
參數如下:(result: Descriptor[]) => void
-
結果
描述元[]
-
傳回
-
Promise<Descriptor[]>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
getIncludedServices()
chrome.bluetoothLowEnergy.getIncludedServices(
serviceId: string,
callback?: function,
): Promise<Service[]>
取得指定服務包含的 GATT 服務清單。
參數
傳回
-
Promise<Service[]>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
getService()
chrome.bluetoothLowEnergy.getService(
serviceId: string,
callback?: function,
): Promise<Service>
取得具有指定執行個體 ID 的 GATT 服務。
傳回
-
Promise<Service>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
getServices()
chrome.bluetoothLowEnergy.getServices(
deviceAddress: string,
callback?: function,
): Promise<Service[]>
取得在遠端裝置上探索到的所有 GATT 服務,並提供裝置位址。
注意:如果裝置尚未完成服務探索,這個 API 會傳回部分服務 (可能為空)。解決方法是新增以時間為準的延遲,和/或重複呼叫,直到傳回預期的服務數量為止。
參數
傳回
-
Promise<Service[]>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
notifyCharacteristicValueChanged()
chrome.bluetoothLowEnergy.notifyCharacteristicValueChanged(
characteristicId: string,
notification: Notification,
callback?: function,
): Promise<void>
將特徵的新值通知遠端裝置。如果通知物件中的 shouldIndicate 旗標為 true,系統會傳送指標而非通知。請注意,如要讓這項呼叫成功,特徵在建立期間必須正確設定「notify」或「indicate」屬性。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
characteristicId
字串
要傳送通知的特徵。
-
通知
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
readCharacteristicValue()
chrome.bluetoothLowEnergy.readCharacteristicValue(
characteristicId: string,
callback?: function,
): Promise<Characteristic>
從遠端周邊裝置擷取指定特徵的值。
參數
-
characteristicId
字串
GATT 特徵的執行個體 ID,其值應從遠端裝置讀取。
-
callback
函式 選用
callback
參數如下:(result: Characteristic) => void
-
結果
-
傳回
-
Promise<Characteristic>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
readDescriptorValue()
chrome.bluetoothLowEnergy.readDescriptorValue(
descriptorId: string,
callback?: function,
): Promise<Descriptor>
從遠端周邊裝置擷取指定特徵描述元的值。
參數
-
descriptorId
字串
GATT 特徵描述元的執行個體 ID,其值應從遠端裝置讀取。
-
callback
函式 選用
callback
參數如下:(result: Descriptor) => void
-
結果
-
傳回
-
Promise<Descriptor>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
registerAdvertisement()
chrome.bluetoothLowEnergy.registerAdvertisement(
advertisement: Advertisement,
callback?: function,
): Promise<number>
建立廣告並註冊廣告。如要呼叫這項函式,應用程式的藍牙:低功耗和藍牙:周邊裝置權限必須設為 true。此外,這個 API 僅適用於資訊站模式中自動啟動的應用程式,或透過設定「--enable-ble-advertising-in-apps」指令列切換開關啟用的應用程式。請參閱 https://developer.chrome.com/apps/manifest/bluetooth 注意:部分硬體支援同時使用中央和周邊模式,但如果硬體不支援,進行這項呼叫會將裝置切換為周邊模式。如果硬體不支援中央和周邊模式,嘗試在兩種模式下使用裝置會導致未定義的行為,或妨礙其他中央角色應用程式正常運作 (包括探索藍牙低功耗裝置)。
參數
-
廣告
要宣傳的廣告。
-
callback
函式 選用
callback
參數如下:(advertisementId: number) => void
-
advertisementId
數字
-
傳回
-
Promise<number>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
registerService()
chrome.bluetoothLowEnergy.registerService(
serviceId: string,
callback?: function,
): Promise<void>
向本機 GATT 伺服器註冊指定服務。如果服務 ID 無效,系統會設定 lastError。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
serviceId
字串
所建立服務的專屬 ID。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
removeService()
chrome.bluetoothLowEnergy.removeService(
serviceId: string,
callback?: function,
): Promise<void>
移除指定服務,並取消註冊 (如果已註冊)。如果服務 ID 無效,系統會設定 lastError。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
serviceId
字串
目前已註冊服務的專屬 ID。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
resetAdvertising()
chrome.bluetoothLowEnergy.resetAdvertising(
callback?: function,
): Promise<void>
重設目前裝置上的廣告。系統會取消註冊並停止所有現有廣告。
參數
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
sendRequestResponse()
chrome.bluetoothLowEnergy.sendRequestResponse(
response: Response,
): void
傳送特徵或描述元讀取/寫入要求的相關回應。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
回應
要求的相關回覆。
setAdvertisingInterval()
chrome.bluetoothLowEnergy.setAdvertisingInterval(
minInterval: number,
maxInterval: number,
callback?: function,
): Promise<void>
設定連續兩則廣告之間的間隔。注意:我們會盡可能完成作業。實際間隔可能與要求間隔有顯著差異。在某些硬體上,間隔時間至少須為 100 毫秒。最小值和最大值不得超過藍牙 4.2 規格允許的範圍。
參數
-
minInterval
數字
廣告間的最小間隔 (以毫秒為單位)。根據規格,這個值不得低於 20 毫秒。
-
maxInterval
數字
廣告間隔上限 (以毫秒為單位)。根據規格,這項值不得超過 10240 毫秒。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
startCharacteristicNotifications()
chrome.bluetoothLowEnergy.startCharacteristicNotifications(
characteristicId: string,
properties?: NotificationProperties,
callback?: function,
): Promise<void>
從指定特徵啟用值通知/指標。啟用後,應用程式就能使用 onCharacteristicValueChanged
事件監聽通知。
參數
-
characteristicId
字串
應啟用通知的 GATT 特徵執行個體 ID。
-
資源
通知工作階段屬性 (選用)。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
stopCharacteristicNotifications()
chrome.bluetoothLowEnergy.stopCharacteristicNotifications(
characteristicId: string,
callback?: function,
): Promise<void>
從指定特徵停用值通知/指標。成功呼叫後,應用程式就會停止接收這項特徵的通知/指標。
參數
-
characteristicId
字串
應用程式通知工作階段應停止的 GATT 特徵執行個體 ID。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
unregisterAdvertisement()
chrome.bluetoothLowEnergy.unregisterAdvertisement(
advertisementId: number,
callback?: function,
): Promise<void>
取消註冊廣告並停止放送。如果廣告無法取消註冊,停止放送廣告的唯一方法可能是重新啟動裝置。
參數
-
advertisementId
數字
要取消註冊的廣告 ID。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
unregisterService()
chrome.bluetoothLowEnergy.unregisterService(
serviceId: string,
callback?: function,
): Promise<void>
向本機 GATT 伺服器取消註冊指定服務。如果服務 ID 無效,系統會設定 lastError。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項函式。並非所有應用程式都能取得周邊裝置權限。
參數
-
serviceId
字串
目前已註冊服務的專屬 ID。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
writeCharacteristicValue()
chrome.bluetoothLowEnergy.writeCharacteristicValue(
characteristicId: string,
value: ArrayBuffer,
callback?: function,
): Promise<void>
從遠端周邊裝置寫入指定特徵的值。
參數
-
characteristicId
字串
要寫入值的 GATT 特徵執行個體 ID。
-
值
ArrayBuffer
應在寫入要求中傳送至遠端特徵的值。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
writeDescriptorValue()
chrome.bluetoothLowEnergy.writeDescriptorValue(
descriptorId: string,
value: ArrayBuffer,
callback?: function,
): Promise<void>
從遠端周邊裝置寫入指定特徵描述元的值。
參數
-
descriptorId
字串
GATT 特徵描述元的執行個體 ID,其值應寫入。
-
值
ArrayBuffer
應在寫入要求中傳送至遠端描述元的值。
-
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
事件
onCharacteristicReadRequest
chrome.bluetoothLowEnergy.onCharacteristicReadRequest.addListener(
callback: function,
)
當連線的中央裝置要求讀取在本機 GATT 伺服器上註冊的特徵值時,系統會觸發這個事件。如果長時間未回覆這項要求,連線可能會中斷。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項事件。並非所有應用程式都能取得周邊裝置權限。
參數
-
callback
函式
callback
參數如下:(request: Request, characteristicId: string) => void
-
申請。
-
characteristicId
字串
-
onCharacteristicValueChanged
chrome.bluetoothLowEnergy.onCharacteristicValueChanged.addListener(
callback: function,
)
當遠端 GATT 特徵的值變更時觸發,可能是因為讀取要求,或是值變更通知/指標。只有在應用程式呼叫 startCharacteristicNotifications
啟用通知時,才會傳送這個事件。
參數
-
callback
函式
callback
參數如下:(characteristic: Characteristic) => void
-
特徵
-
onCharacteristicWriteRequest
chrome.bluetoothLowEnergy.onCharacteristicWriteRequest.addListener(
callback: function,
)
當連線的中央裝置要求寫入在本機 GATT 伺服器上註冊的特徵值時,系統會觸發這個事件。如果長時間未回覆這項要求,連線可能會中斷。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項事件。並非所有應用程式都能取得周邊裝置權限。
參數
-
callback
函式
callback
參數如下:(request: Request, characteristicId: string) => void
-
申請。
-
characteristicId
字串
-
onDescriptorReadRequest
chrome.bluetoothLowEnergy.onDescriptorReadRequest.addListener(
callback: function,
)
當連線的中央裝置要求讀取在本機 GATT 伺服器上註冊的描述元值時,系統會觸發這個事件。如果長時間未回覆這項要求,連線可能會中斷。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項事件。並非所有應用程式都能取得周邊裝置權限。
參數
-
callback
函式
callback
參數如下:(request: Request, descriptorId: string) => void
-
申請。
-
descriptorId
字串
-
onDescriptorValueChanged
chrome.bluetoothLowEnergy.onDescriptorValueChanged.addListener(
callback: function,
)
當遠端 GATT 特徵描述元的值變更時觸發,通常是讀取要求所致。這個事件主要是為了方便起見,且一律會在成功呼叫 readDescriptorValue
後傳送。
參數
-
callback
函式
callback
參數如下:(descriptor: Descriptor) => void
-
描述元
-
onDescriptorWriteRequest
chrome.bluetoothLowEnergy.onDescriptorWriteRequest.addListener(
callback: function,
)
當連線的中央裝置要求寫入在本機 GATT 伺服器上註冊的描述元值時,就會觸發這個事件。如果長時間未回覆這項要求,連線可能會中斷。只有在應用程式的 bluetooth:low_energy 和 bluetooth:peripheral 權限都設為 true 時,才能使用這項事件。並非所有應用程式都能取得周邊裝置權限。
參數
-
callback
函式
callback
參數如下:(request: Request, descriptorId: string) => void
-
申請。
-
descriptorId
字串
-
onServiceAdded
chrome.bluetoothLowEnergy.onServiceAdded.addListener(
callback: function,
)
在遠端裝置上發現新的 GATT 服務時觸發。
onServiceChanged
chrome.bluetoothLowEnergy.onServiceChanged.addListener(
callback: function,
)
當遠端 GATT 服務的狀態變更時,系統會觸發這個事件。這包括從服務新增或移除的任何特徵和/或描述元,以及來自遠端裝置的「ServiceChanged」通知。
onServiceRemoved
chrome.bluetoothLowEnergy.onServiceRemoved.addListener(
callback: function,
)
當遠端裝置上先前探索到的 GATT 服務已移除時,系統會觸發這個事件。