У меня есть эта функция для подключения приложения, которое я разрабатываю, к другому устройству с поддержкой BLE:
public boolean connecttoDevice(int position) {
currentDevice = devices.get(position);
final BluetoothManager bluetoothManager = (BluetoothManager) _client
.getSystemService(Context.BLUETOOTH_SERVICE);
if(currentDevice != null
&& bluetoothManager.getConnectionState(currentDevice, BluetoothProfile.GATT) != BluetoothProfile.STATE_CONNECTED
&& bluetoothManager.getConnectionState(currentDevice, BluetoothProfile.GATT) != BluetoothProfile.STATE_CONNECTING
){
mBluetoothGatt = currentDevice.connectGatt(_client, false, mGattCallback);
System.out.println(currentDevice.getName()+":"+currentDevice.getAddress());
System.out.println(bluetoothManager.getConnectionState(currentDevice, BluetoothProfile.GATT));
}
else return false;
return !(mBluetoothGatt == null);
}
_client
— это действие, вызывающее этот метод. Я обнаружил, что после вызова метода состояние подключения устройства вообще не меняется, а обратный вызов никогда не вызывается. Мне просто интересно, где это пошло не так?
Спасибо, Боб