为了保护隐私,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, boolean autoConnect,
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