android蓝牙重新打开,android – 如何在每个打开同一个蓝牙低能量设备时重新连接我的应用程序?...

为了保护隐私,mac地址不断变化 – 请参考下面的代码片段:

5.4.5 Privacy Feature

Bluetooth LE supports a feature that reduces the ability to track a LE device over a period of time by changing the

Bluetooth device address on a frequent basis. The privacy feature is

not used in the GAP discovery mode and procedures but it is used,when

supported,during connection mode and connection procedures. In order

for a device using the privacy feature to reconnect to known devices,

the device address,referred to as the private address,must be

resolvable by the other device.

The private address is generated using

the device’s resolving identity key (IRK) exchanged during the bonding

procedure.

所以理想的方法是使用IRK来实现设备的实际地址.但是我没有找到任何API来做.

目前,我在mny应用程序中使用的工作重新连接到设备,

>循环遍历所有可用的设备.

>获得序列号,如果序列号不匹配已存储的号码

然后断开连接.

>对所有设备重复步骤2.

如果设备通过某些服务暴露了序列号,这项工作将会起作用.

从文档:

public BluetoothGatt connectGatt (Context context,

BluetoothGattCallback callback) Added in API level 18

Connect to GATT Server hosted by this device. Caller acts as GATT

client. The callback is used to deliver results to Caller,such as

connection status as well as any further GATT client operations. The

method returns a BluetoothGatt instance. You can use BluetoothGatt to

conduct GATT client operations. Parameters

autoConnect Whether to

directly connect to the remote device (false) or to automatically

connect as soon as the remote device becomes available (true).

callback GATT callback handler that will receive asynchronous callbacks. Throws IllegalArgumentException if callback is null

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值