Every Connection Request Is Being Treated As Direct Connect Request + Android Ble
Solution 1:
The problem has been fixed in the master android branch, May 2016. There are mixed reports about whether it has ended up in Nougat or not, possibly device dependent, but it is definitely still a bug in Marshmallow.
The reflection code required to do the workaround quickly becomes complicated because the classes IBluetoothManager and IBluetoothGatt are not available in user code.
Fortunately, someone has already written a very small, clear library which does this exact routine for us.
Using this class, one need only call:
mBluetoothGatt = (new BleConnectionCompat(context)).connectGatt(device, autoConnect, callback)
instead of
mBluetoothGatt = device.connectGatt(context, autoConnect, callback);
It is working beautifully for me. I take no credit whatsoever for this, it is entirely the work of uKL
Also, note it is under Apache License 2.0 Copyright 2016 Polidea Sp. z o.o
Solution 2:
The problem is a race condition described here: https://code.google.com/p/android/issues/detail?id=69834
A possible solution until they fix it (will they?) is to use reflection to manually construct a gatt object, set the mAutoConnect flag to true and call connect.
Post a Comment for "Every Connection Request Is Being Treated As Direct Connect Request + Android Ble"