简体   繁体   中英

How to detect when a connected BLE device change its name?

I am using Bluetooth low energy to exchange data with an electronic card. During the data exchange, the card can sometimes change its device name to a new one, I am looking a way too detect when this name is modified.

I store the name and the MAC address of this device whhen I connect to the device at the beginning but it seems that android don't see that the name of the deviceas changed. Actually, when I triedto read the name it return me the old name andnot the new one.

this example is called at every data exchange with the electronic card, and every time, it return me the old name, even after the card change its name :

        BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
        List<BluetoothDevice> devices = bluetoothManager.getConnectedDevices(BluetoothProfile.GATT);
        for(BluetoothDevice device : devices) {
            Log.i("BLE_device_name : ",device.getName());
        }

Is there any listener for this ? Or a method to force Android to get the real BLE name and not the memorized one ?

The only solution I see is to make a new Bluetooth scan but it's too long for my process..

thank you

If you aren't connected, you can issue a scan and check the advertisement data what the name is (if it is included).

If you are connected, you can read the GATT characteristic containing the name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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