我有这个函数来调用将我正在开发的应用程序连接到另一个支持 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
是调用此方法的活动。我发现调用该方法后,设备的连接状态根本没有改变,并且从未调用过回调。我只是想知道它哪里出错了?
谢谢,鲍勃