Flutter - flutter_blue library connection issue
Permissions appear not to be the issue. It finds the ble devices.
I experienced similar issues with flutter_blue on android. It even appeared to be BLE device dependent. It connected fine to some devices, and didn't for others.
In my case, it was just stuck at the connection attempt. Waiting several minutes resolved mostly in a connection, but that's not usable.
I was able to resolve my issue, by turning off autoconnect, so
device.connect(autoConnect: false);
Then it worked for me. Maybe this helps you or other users experiencing the same issues.
serdar aylanc
Updated on December 06, 2022Comments
-
serdar aylanc over 1 year
I am running flutter_blue example app on an android device, but scans and find the ble devices nearby but unable to connect them. iOS build of example app can successfully connect the ble devices. Is there a missing configuration for android devices.
Note: I checked permissions, they are ok.
-
BorisBaroslav almost 4 yearsSidenote for anyone else seeing this: Android unfortunately requires location permissions to be able to scan for BLE devices. Reasons for this are mostly location services, that rely on BLE scans, e.g. for indoor navigation.
-
Sami Issa about 3 yearsThis suggestion didn't solve my problem. I can find the device but sometimes can't connect or take long time to establish the connection. This is my connection code snippet: await deviceToConnect .connect(autoConnect: false) .timeout( Duration(seconds: kBleTimeoutConn), onTimeout: () => onTimeOut(), ) .then( (value) async { await checkCurrentState(); if (deviceState == BluetoothDeviceState.connected) { connectionSetup(onConnected: onConnected); } }, );
-
DNS about 3 yearsdid you guys find any solution?