onServicesDiscovered not be called on BluetoothGattCallback
Asked Answered
C

2

0

I start working with ibeacon and android. But there are some problem need for your helps. On blutoothGatCallback I implement onConnectionStateChange and call discoverServices(). Althougth, discoverServices() return true but there is not any callback execute, I hope onServicesDiscovered being called, but not.

@Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status,
            int newState) {
        Log.i(TAG, "onConnectionStateChange : " + status + "  newState : "
                + newState);
        if (newState == BluetoothProfile.STATE_CONNECTED) {

            boolean isdiscover= mBluetoothGatt.discoverServices();
            if(isdiscover){
            mConnected = true;              
            }
        } 

    }

Status is 133 and newstate is connected. Does status make it fail to get callback

Camelback answered 10/7, 2015 at 3:21 Comment(2)
the 0x85 as status indicates an error, and thus you should figure out why you are getting it, and then it should work fineTangential
Please note the manufacturer and model of iBeacon you are using. Not all iBeacon implementations support GATT services, so it may be that you are not supposed to be able to connect.Heteroecious
B
2

More information would be helpful, can you supply the received Advertisement data?

The following is just a guess as theres a broad range of issues around with Android BLE, however i seen this general 133 error already when accidentally issuing a BR/EDR connection to a Beacon.

As Android defaults to a BR/EDR connection when the GATT-server device advertises support for it, you can try to explicitely set the transport to TRANSPORT_LE in connectGatt(), however since this parameter is only aviable in the hidden version of it, you need to use reflection.

Try to issue the connection like this:

private BluetoothGatt mGatt;
private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() { ... }

public void connectToDevice(BluetoothDevice device) {
        try {
            Method m = device.getClass().getDeclaredMethod("connectGatt", Context.class, boolean.class, BluetoothGattCallback.class, int.class);
            int transport = device.getClass().getDeclaredField("TRANSPORT_LE").getInt(null);
            mGatt = (BluetoothGatt) m.invoke(device, this, false, gattCallback, transport);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

That way you can at least be sure its not related to this Android behaviour.

Breve answered 12/7, 2015 at 15:14 Comment(0)
D
1

Status 133 can indicate that you try to execute bt commands on a non-main thread.

The BTLE callbacks are called from android-bt-binder threads.

So

mBluetoothGatt.discoverServices();

runs on the binder thread and it should run on the GUI/main thread

Digiacomo answered 2/8, 2016 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.