I have a button to initiate the connection and that will later write to a Characaristic. Here's the code:
public void sendMessage(View view) {
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("Device MAC");
device.connectGatt(this, false, mGattCallback, 2);
//connectToDevice(device);
}
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {...
Problem is, onConnectionStateChange is not called. I tried using reflection to make a connection as explained here: BluetoothDevice.ConnectGatt() with transport parameter but it didn't work. This is what I get in the debug console:
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=12 D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=12 device=8E:4D:4B:10:AC:E6 D/BluetoothGatt: onClientConnParamsChanged() - Device=8E:4D:4B:10:AC:E6 interval=6 status=0 D/BluetoothGatt: onClientConnParamsChanged() - Device=8E:4D:4B:10:AC:E6 interval=30 status=0
Any suggestions? Thanks.