2

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

谢谢,鲍勃

4

1 回答 1

0

不用麻烦,API暂时有个bug,如果你要连接BT classic和BLE双模设备,连接会失败。

于 2013-09-09T16:19:36.600 回答