I am trying to build an Android application which acts as a BLE peripheral and also as GATT client.
These are the steps I am trying to achieve:
The Android device starts advertising itself. A second device starts scanning and as soon as it detects the android device it initiates a connection.
The Android devices acts as a GATT client and tries to connect to the server device.
The first step seems to work fine, I am able to advertise and the other device (a Bluegiga Evalboard in my case) is able to see the Android device and can establish a connection.
But how am I notified on the Android device that a connection could be established in order to call the function device.connectGatt(context, false, gattCb) to connect to the GATT server?
I also tried it by obtaining the remote device after starting the advertisement.
BluetoothDevice device = bleAdapter.getRemoteDevice(remoteAddress);
device.connectGatt(context, false, gattCb);
The only thing that happens, the onConnectionStateChange(BluetoothGatt gatt, int status, int newState) function gets called called from the BluetoothGattCallback just to inform me that the device has disconnected.
What am I missing?