Flutter, how do I display Bluetooth device names in a Flutter app?

1.2k Views Asked by At

I'm currently working on a Flutter application that requires connecting to Bluetooth devices. I'm using the flutter_blue package to handle the connection.

My issue is that I'm unable to display the names of certain Bluetooth devices in the application. I've noticed that only the names of TVs are showing up, but not those of other devices. My main goal is to connect to ESP32 microcontrollers.

Here's what I've already tried:

-I checked that my phone could detect these Bluetooth devices outside of the application. -I consulted the documentation of the flutter_blue package and searched for similar issues on forums, but I didn't find a solution. -I verified the Bluetooth permissions in the AndroidManifest.xml file. -I expected that all detected Bluetooth devices would be listed with their names. However, some devices are not visible.

Do you have any suggestions for resolving this issue with displaying the names of Bluetooth devices in my Flutter application?

Thank you very much for your help!

2

There are 2 best solutions below

0
Risto On

A Bluetooth LE device can, but does not have to, transmit its name in the Advertising PDU. If no name is available, the MAC address of the device can be used instead.

0
Minhal On

There are a few possibilities that you might need to reboot your device, you might need to put your device in "discovery mode", your phone may have already connected automatically, another app may have already connected to your phone may have already connected to your device Try looking through already connected devices:

Code Example:

//Search already connected devices, including devices
// connected to other apps
 List<BluetoothDevice> system = await 
 FlutterBluePlus.connectedSystemDevices;
 for (var d in system) {
 print('${r.device.localName} already connected to! ${r.device.remoteId}');
   if (d.localName == "myBleDevice") {
     await r.connect(); // must connect our app
     }
   }

. Maybe your scan filters are wrong. Try removing all scan filters, for withServices to work, your device must actively advertise the serviceUUIDs it supports.