I'm trying to connect my Beacons to the Gattservice. In the Callback onConnectionStateChange, It's always failing and im getting the
statuscodes 133 and 257.
Somehwere was written that 133 stands for to many connections. In my code there are lines with gatt.disconnect(). I don't know how to fix it, because all other gattexamples are the same. I'm working with the Android 6.0.1 Version and the API 23, if it's important to find the error. Here's my code:
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if(status == BluetoothGatt.GATT_SUCCESS) {
switch (newState) {
case BluetoothProfile.STATE_CONNECTED:
mBleDevices.add(gatt.getDevice());
Log.i("Beacons", "STATE_CONNECTED");
runOnUiThread(new Runnable() {
@Override
public void run() {
mBluetoothGatt.discoverServices();
}
});
break;
case BluetoothProfile.STATE_DISCONNECTED:
Log.e("Beacons", "STATE_DISCONNECTED");
mBleDevices.remove(gatt.getDevice());
mBluetoothGatt.disconnect();
mBluetoothGatt = null;
break;
default:
Log.e("Beacons", "STATE_OTHER");
}
} else {
Log.e("Beacons", "ERROR WITH CONNECTING " + status);
mBleDevices.remove(gatt.getDevice());
}
}
My ScanCallback looks like this:
public void onScanResult(int callbackType, ScanResult result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
BluetoothDevice btDevice = result.getDevice();
connectToDevice(btDevice);
}
});
}
And starting connection like this:
runOnUiThread(new Runnable() {
@Override
public void run() {
mBluetoothGatt = btDevice.connectGatt(getApplicationContext(), true, connectCallback);
}
});
The connectCallback causes then onConnectionStateChange function. Thank you for your help!