0

我希望连接的设备在不扫描蓝牙的情况下获取BluetoothDevice设备信息,所以我存储了所有蓝牙连接的设备。

然而,虽然其他设备的行为与预期相同,但当手机重新启动时,一种类型的蓝牙设备会丢失其配对信息。

有谁知道为什么会发生这种情况,或者有另一种方法可以在不扫描的情况下获取蓝牙设备信息?

4

1 回答 1

0

您可以使用蓝牙适配器。

BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(mac);
device.connectGatt(mContext, false, mGattCallback);

// TODO your code

如果蓝牙设备不在身边,in BluetoothGattCallback'sonConnectionStateChange会报告BluetoothGatt.STATE_DISCONNECTED

BluetoothDevice 的创建者具有包范围。但是BluetoothAdapter的getRemoteDevice的源码是:

public BluetoothDevice getRemoteDevice(String address) {
    return new BluetoothDevice(address);
}
于 2017-11-15T07:12:06.320 回答