My application has issues when it comes to connecting to BluetoothGatt on certain devices.
All the BLE related code resides in an android Service
and everything works fine except on Huawei CAM-L03. Some old Samsung Galaxy devices also have been reported to have issues.
I have discovered recently, that on some devices all the BLE communications must be performed on the UI thread. I wrote a quick test application and the Huawei problems are gone when everything runs on the UI thread.
I’ve tried creating a Handler
in the Service
with the main looper:
final Context context = getApplicationContext();
Handler handler = new Handler(context.getMainLooper());
handler.post(new Runnable(){
@Override
public void run() {
BluetoothGatt gatt = device.connectGatt(context, false, callBackHandler);
…
}
});
But that still gives me GATT_ERROR 133 in the connection callback, which I kind of suspected since the context is the service, not the UI app.
I only see two options here:
- List item Don’t support certain devices
- Move everything to the UI app to support all devices
I’m not content with either of these. Are there other options that I don’t know about?