说明
chrome.bluetoothLowEnergy
API 用于通过通用属性配置文件 (GATT) 与 Bluetooth Smart(低功耗)设备进行通信。
清单
类型
Advertisement
属性
-
manufacturerData
ManufacturerData[] 可选
要包含在广告数据的“制造商特定数据”字段中的制造商特定数据列表。
-
serviceData
ServiceData[] 可选
要包含在广告数据的“服务数据”字段中的服务数据列表。
-
serviceUuids
string[] 可选
要包含在广告数据的“服务 UUID”字段中的 UUID 列表。这些 UUID 可以采用 16 位、32 位或 128 位格式。
-
solicitUuids
string[] 可选
要包含在广告数据的“Solicit UUIDs”字段中的 UUID 列表。这些 UUID 可以采用 16 位、32 位或 128 位格式。
-
广告类型。
AdvertisementType
广告类型。如果选择“广播”,则发送的广告类型将为 ADV_NONCONN_IND,并且设备将使用随机 MAC 地址进行广播。如果设置为“peripheral”,广告类型将为 ADV_IND 或 ADV_SCAN_IND,并且设备将使用真实的蓝牙适配器 MAC 地址进行广播。
枚举
“broadcast”
“外围设备”
Characteristic
属性
-
instanceId
字符串(选填)
返回分配给相应特征的标识符。使用实例 ID 来区分来自具有相同 UUID 的外围设备的特征,并进行接受特征标识符的函数调用。如果此实例表示远程特征,则为 true。
-
媒体资源
相应特征的属性。
-
服务
服务(可选)
相应特征所属的 GATT 服务。
-
uuid
字符串
特征的 UUID,例如 00002a37-0000-1000-8000-00805f9b34fb。
-
值
ArrayBuffer 可选
当前缓存的特征值。当通过通知或指示读取或更新特征的值时,此值会更新。
CharacteristicProperty
表示特征可能属性的值。特征权限是从这些属性推断出来的。请参阅蓝牙 4.x 规范,了解每个属性的含义。
枚举
“broadcast”
“read”
"writeWithoutResponse"
“写入”
“notify”
“指示”
"authenticatedSignedWrites"
"extendedProperties"
“reliableWrite”
"writableAuxiliaries"
“encryptRead”
“encryptWrite”
"encryptAuthenticatedRead"
"encryptAuthenticatedWrite"
ConnectProperties
属性
-
持久性
布尔值
标志,用于指示当应用的事件页面卸载时,是否保持与设备的连接处于打开状态(请参阅管理应用生命周期)。默认值为
false.
。
Descriptor
属性
-
特征
特征(可选)
相应描述符所属的 GATT 特征。
-
instanceId
字符串(选填)
返回分配给此描述符的标识符。使用实例 ID 来区分来自具有相同 UUID 的外围设备的描述符,并进行接受描述符标识符的函数调用。如果此实例表示远程特征,则为 true。
-
权限Chrome 52 及更高版本
相应描述符的权限。
-
uuid
字符串
特征描述符的 UUID,例如 00002902-0000-1000-8000-00805f9b34fb。
-
值
ArrayBuffer 可选
当前缓存的描述符值。读取描述符的值时,此值会更新。
DescriptorPermission
表示描述符可能具备的权限的值。请参阅蓝牙 4.x 规范,了解每项权限的具体含义。
枚举
“read”
“写入”
"encryptedRead"
"encryptedWrite"
"encryptedAuthenticatedRead"
"encryptedAuthenticatedWrite"
Device
属性
-
地址
字符串
设备的地址,格式为“XX:XX:XX:XX:XX:XX”。
-
deviceClass
number 可选
设备的类别,由 http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband 定义的位字段。
-
name
字符串(选填)
设备的简明易懂的名称。
ManufacturerData
属性
-
数据
number[]
-
id
数值
Notification
属性
-
shouldIndicate
布尔值(可选)
用于发送指示而非通知的可选标志。
-
值
ArrayBuffer
特征的新值。
NotificationProperties
属性
-
持久性
布尔值
一个标志,用于指示当应用的应用事件页面卸载时,应用是否应接收通知(请参阅管理应用生命周期)。默认值为
false
。
Request
属性
-
设备
发送此请求的设备。
-
requestId
数值
相应请求的唯一 ID。在回复此请求时使用此 ID。
-
值
ArrayBuffer 可选
要写入的值(如果这是写入请求)。
Response
属性
-
isError
布尔值
如果这是错误响应,则应为 true。
-
requestId
数值
相应请求的 ID。
-
值
ArrayBuffer 可选
回答值。写入请求和错误响应将忽略此参数。
Service
属性
-
deviceAddress
字符串(选填)
GATT 服务所属的远程外围设备的设备地址。如果此实例表示远程服务,则存在。
-
instanceId
字符串(选填)
返回分配给相应服务的标识符。使用实例 ID 区分来自具有相同 UUID 的外围设备的多个服务,并进行需要服务标识符的函数调用。如果此实例表示远程服务,则存在。
-
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 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
disconnect()
chrome.bluetoothLowEnergy.disconnect(
deviceAddress: string,
callback?: function,
): Promise<void>
关闭应用与具有指定地址的设备的连接。请注意,这并不总是会销毁物理链接本身,因为可能还有其他应用具有打开的连接。
参数
-
deviceAddress
字符串
远程设备的蓝牙地址。
-
callback
函数 可选
callback
参数如下所示:() => void
返回
-
Promise<void>
Chrome 91 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
getIncludedServices()
chrome.bluetoothLowEnergy.getIncludedServices(
serviceId: string,
callback?: function,
): Promise<Service[]>
获取给定服务所包含的 GATT 服务列表。
参数
返回
-
Promise<Service[]>
Chrome 91 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
getService()
chrome.bluetoothLowEnergy.getService(
serviceId: string,
callback?: function,
): Promise<Service>
获取具有指定实例 ID 的 GATT 服务。
参数
-
serviceId
字符串
所请求的 GATT 服务的实例 ID。
-
callback
函数 可选
callback
参数如下所示:(result: Service) => void
-
结果
-
返回
-
Promise<Service>
Chrome 91 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
getServices()
chrome.bluetoothLowEnergy.getServices(
deviceAddress: string,
callback?: function,
): Promise<Service[]>
获取在具有指定设备地址的远程设备上发现的所有 GATT 服务。
注意:如果设备上的服务发现尚未完成,此 API 将返回部分(可能为空)服务。一种解决方法是添加基于时间的延迟和/或重复调用,直到返回预期数量的服务。
参数
返回
-
Promise<Service[]>
Chrome 91 及更高版本仅 Manifest 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 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
readCharacteristicValue()
chrome.bluetoothLowEnergy.readCharacteristicValue(
characteristicId: string,
callback?: function,
): Promise<Characteristic>
从远程外围设备检索指定特征的值。
参数
-
characteristicId
字符串
应从远程设备读取值的 GATT 特征的实例 ID。
-
callback
函数 可选
callback
参数如下所示:(result: Characteristic) => void
-
结果
-
返回
-
Promise<Characteristic>
Chrome 91 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
readDescriptorValue()
chrome.bluetoothLowEnergy.readDescriptorValue(
descriptorId: string,
callback?: function,
): Promise<Descriptor>
从远程外围设备检索指定特征描述符的值。
参数
-
descriptorId
字符串
应从远程设备读取值的 GATT 特征描述符的实例 ID。
-
callback
函数 可选
callback
参数如下所示:(result: Descriptor) => void
-
结果
-
返回
-
Promise<Descriptor>
Chrome 91 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
registerAdvertisement()
chrome.bluetoothLowEnergy.registerAdvertisement(
advertisement: Advertisement,
callback?: function,
): Promise<number>
创建广告并注册以用于广告宣传。如需调用此函数,应用必须将 bluetooth:low_energy 和 bluetooth:peripheral 权限设置为 true。此外,此 API 仅适用于在自助服务终端模式下自动启动的应用,或者通过设置“--enable-ble-advertising-in-apps”命令行开关来使用。请参阅 https://developer.chrome.com/apps/manifest/bluetooth 注意:在某些硬件上,支持同时使用中心模式和外围模式,但在不支持此功能的硬件上,进行此调用会将设备切换到外围模式。如果硬件不支持中心模式和外围模式,尝试在两种模式下使用设备会导致未定义的行为,或阻止其他中心角色应用正常运行(包括发现蓝牙低功耗设备)。
参数
-
广告
要宣传的广告。
-
callback
函数 可选
callback
参数如下所示:(advertisementId: number) => void
-
advertisementId
数值
-
返回
-
Promise<number>
Chrome 91 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
resetAdvertising()
chrome.bluetoothLowEnergy.resetAdvertising(
callback?: function,
): Promise<void>
重置当前设备上的广告。系统将取消注册并停止所有现有广告。
参数
-
callback
函数 可选
callback
参数如下所示:() => void
返回
-
Promise<void>
Chrome 91 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
sendRequestResponse()
chrome.bluetoothLowEnergy.sendRequestResponse(
response: Response,
): void
针对特征或描述符读取/写入请求发送响应。仅当应用同时将 bluetooth:low_energy 和 bluetooth:peripheral 权限设置为 true 时,此函数才可用。外围设备权限可能不适用于所有应用。
参数
-
Response
对请求的响应。
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 及更高版本仅 Manifest 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 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
stopCharacteristicNotifications()
chrome.bluetoothLowEnergy.stopCharacteristicNotifications(
characteristicId: string,
callback?: function,
): Promise<void>
停用来自指定特征的值通知/指示。成功调用后,应用将停止接收来自此特征的通知/指示。
参数
-
characteristicId
字符串
应用通知会话应停止的 GATT 特征的实例 ID。
-
callback
函数 可选
callback
参数如下所示:() => void
返回
-
Promise<void>
Chrome 91 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
unregisterAdvertisement()
chrome.bluetoothLowEnergy.unregisterAdvertisement(
advertisementId: number,
callback?: function,
): Promise<void>
取消注册广告并停止其广告。如果广告无法取消注册,停止广告的唯一方法可能是重启设备。
参数
-
advertisementId
数值
要取消注册的广告的 ID。
-
callback
函数 可选
callback
参数如下所示:() => void
返回
-
Promise<void>
Chrome 91 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest 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 及更高版本仅 Manifest V3 及更高版本支持 Promise,其他平台需要使用回调。
事件
onCharacteristicReadRequest
chrome.bluetoothLowEnergy.onCharacteristicReadRequest.addListener(
callback: function,
)
当已连接的中央设备请求读取本地 GATT 服务器上注册的特征值时触发。长时间不回复此请求可能会导致连接断开。仅当应用同时将 bluetooth:low_energy 和 bluetooth:peripheral 权限设置为 true 时,此事件才可用。外围设备权限可能不适用于所有应用。
参数
-
callback
函数
callback
参数如下所示:(request: Request, characteristicId: string) => void
-
request
-
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
-
request
-
characteristicId
字符串
-
onDescriptorReadRequest
chrome.bluetoothLowEnergy.onDescriptorReadRequest.addListener(
callback: function,
)
当已连接的中央设备请求读取在本地 GATT 服务器上注册的描述符的值时触发。长时间不回复此请求可能会导致连接断开。仅当应用同时将 bluetooth:low_energy 和 bluetooth:peripheral 权限设置为 true 时,此事件才可用。外围设备权限可能不适用于所有应用。
参数
-
callback
函数
callback
参数如下所示:(request: Request, descriptorId: string) => void
-
request
-
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
-
request
-
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 服务被移除时触发。