Running example app on Android 6.0, I get this exception when scan is initiated.
D/BluetoothDevice(11526): mAddress: 25:0A:C4:0C:FF:2C
D/BluetoothDevice(11526): getName: name = MyBLE
D/BluetoothDevice(11526): getType: type = 2
D/AndroidRuntime(11526): Shutting down VM
E/AndroidRuntime(11526): FATAL EXCEPTION: main
E/AndroidRuntime(11526): Process: com.pauldemarco.flutterblueexample, PID: 11526
E/AndroidRuntime(11526): java.lang.ArrayIndexOutOfBoundsException: Not enough data.
E/AndroidRuntime(11526): at com.pauldemarco.flutterblue.AdvertisementParser.parse(AdvertisementParser.java:60)
E/AndroidRuntime(11526): at com.pauldemarco.flutterblue.ProtoMaker.from(ProtoMaker.java:30)
E/AndroidRuntime(11526): at com.pauldemarco.flutterblue.FlutterBluePlugin$2.onScanResult(FlutterBluePlugin.java:625)
E/AndroidRuntime(11526): at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper$1.run(BluetoothLeScanner.java:362)
E/AndroidRuntime(11526): at android.os.Handler.handleCallback(Handler.java:815)
E/AndroidRuntime(11526): at android.os.Handler.dispatchMessage(Handler.java:104)
E/AndroidRuntime(11526): at android.os.Looper.loop(Looper.java:207)
E/AndroidRuntime(11526): at android.app.ActivityThread.main(ActivityThread.java:5728)
E/AndroidRuntime(11526): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11526): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
E/AndroidRuntime(11526): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
I got the same issue, with a specific hardware device in development. There are two times a long local name (Type 9) in it and no Type 8 part (for the short local name). In the Android part of the lib, the implementation of the AdvertismentParser breaks out of the loop as soon as it founds a second local long name, without moving the position in the bytestream to parse further.
I tried a change in code _locally_ adding one line, to get it run through, and it works for this case now, too:
(flutter_blue-0.3.3/android/src/main/java/com/pauldemarco/flutterblue/AdvertismentParser)
case 0x09: { // Long local name.
if (seenLongLocalName) {
// Prefer the long name over the short.
data.position(data.position() + length); // <-- new line
break;
}
Although I think it would be fine, to not throw the exception, but to skip the device entirely. The hardware is not setup correctly, so I guess it would be fine for the use case of this lib,
Hi, I wanted to bump this back up to see if anyone was able to figure out another solution. I am trying to connect to my ESP32 dev board, and that is exactly the device that crashes the app when a scan is initiated--scanning is perfectly fine if . Running the scan by itself is fine and it produces a _ControllerStream
Is there a way to simply connect to board manually if I know the MAC address? I wasn't able to get it working and I read somewhere that for iOS you have to scan then connect for BLE.
@gautam-chebrolu
@MSchrenker
Hey im having the same issue! have you found a solution?
@MSchrenker Is it possible to know where to set that said short name entry? (esp32 noob)
@lemonbuzz We modified the Arduino sample from here:
https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLETests/Arduino/BLE_notify/BLE_notify.ino
and replaced:
// Start advertising pServer->getAdvertising()->start();
with something like this:
// Start advertising
//pServer->getAdvertising()->start();
BLEAdvertising* pAdvertising = pServer->getAdvertising();
BLEAdvertisementData data;
data.setFlags(ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT);
data.setName("2nd Server");
data.setShortName("4th Server");
pAdvertising->setAdvertisementData(data);
pAdvertising->start();
@MSchrenker Thank you very much! Your solution of Apr 13 works perfect.
This looks to be caused by any devices that advertise more than 1 "Complete Local Name 0x09" packet. PR #90 should fix this.
I will close this for now, please re-open if the problem persists.
Most helpful comment
I got the same issue, with a specific hardware device in development. There are two times a long local name (Type 9) in it and no Type 8 part (for the short local name). In the Android part of the lib, the implementation of the AdvertismentParser breaks out of the loop as soon as it founds a second local long name, without moving the position in the bytestream to parse further.
I tried a change in code _locally_ adding one line, to get it run through, and it works for this case now, too:
(flutter_blue-0.3.3/android/src/main/java/com/pauldemarco/flutterblue/AdvertismentParser)
Although I think it would be fine, to not throw the exception, but to skip the device entirely. The hardware is not setup correctly, so I guess it would be fine for the use case of this lib,