Search code examples
androidflutterbluetoothbluetooth-lowenergyandroid-bluetooth

Flutter_Blue can't scan my device. (My BT speaker) Android


I'm new to Flutter and I'm working on a project that needs Bluetooth to connect to my hardware. To my knowledge, Flutter_Blue works like this:

  1. Get Flutter_Blue instance
  2. Start scanning with scan(), also hook a listener to listen for new devices. (Which will return ScanedDevice, then add it to my list.)
  3. From my list, pick a device I want to connect to, with await device.connect()
  4. After a successful connection, discover its services with device.discoverServices()
  5. for characteristics in service.characteristics to get characteristics from that device.
  6. use characteristic.read().listen((value){//do something with value});

And I kept failing at stage 2, which is scanning for devices. I somehow can't find my Bluetooth_Speaker with scan(), I tried using different scanning modes(Low latency, Low Energy, Balanced).

I can find other devices easily which is not mine(But they somehow don't have a name, all IDs are unique). I have tried using my friend's phone as a device for my app to scan, but still no result.

With my android Bluetooth settings page, I can find the Bluetooth speaker (also my friend's phone) in the scanning new devices page.

Please tell me what went wrong I'll be very thankful. Thank you.

Environment:

  • Sony XZ2 (Android version: 9)
  • Flutter version: 2.0.5
  • Dart version: 2.12.3
  • sdk: ">=2.7.0 <3.0.0"
  • flutter_blue: 0.6.3+1
  • IDE: VSCode

Compile method: flutter run

Learned lesson(s) after viewing the replies:

  1. Bluetooth_Low_Energy(BLE) cannot discover/connect to Classic Bluetooth. nor the other way(Classic -> BLE).

Solution

  • Bluetooth has two types

    • Classic
    • Low Energy(LE)

    Bluetooth_Low_Energy(BLE) is a technique that offers lower energy consumption, with a trade-off of slower transmission speed. Classic devices can offer 24Mbps, where Low_Energy only offers 1Mbps.

    These two types of Bluetooth cannot be connected to each other.

    In this case, Flutter's Flutter_Blue library uses the Low_Energy service, and the Bluetooth speaker is used as a Classic device, That's why Flutter_Blue cannot scan/discover the speaker.