简体   繁体   English

设备重启后,与Android配对的蓝牙消失

[英]Android paired Bluetooth disappears when device reboots

I want the connected device to get BluetoothDevice device information without scanning Bluetooth, so I store all Bluetooth-connected devices. 我希望连接的设备在不扫描蓝牙的情况下获取BluetoothDevice设备的信息,因此我存储了所有连接Bluetooth的设备。

However, while other devices behave as expected, one type of Bluetooth devices will lose their paired information when the phone is rebooted. 但是,虽然其他设备的运行情况与预期的一样,但是一种类型的蓝牙设备在重新启动手机后会丢失其配对信息。

Do anyone know why this may happen or have an alternative way to obtain Bluetooth Device information without scanning? 有谁知道为什么会发生这种情况,或者有其他方法无需扫描即可获取蓝牙设备信息?

You can use BluetoothAdapter. 您可以使用BluetoothAdapter。

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

// TODO your code

If the bluetooth device is not around, in BluetoothGattCallback 's onConnectionStateChange will report BluetoothGatt.STATE_DISCONNECTED . 如果蓝牙设备不在附近,则在BluetoothGattCallbackonConnectionStateChange中将报告BluetoothGatt.STATE_DISCONNECTED

BluetoothDevice's creator has packages scope. BluetoothDevice的创建者具有包范围。 But the source code of BluetoothAdapter's getRemoteDevice is: 但是BluetoothAdapter的getRemoteDevice的源代码是:

public BluetoothDevice getRemoteDevice(String address) {
    return new BluetoothDevice(address);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM