Как подключиться к серверу GATT с помощью Android BLE API?

У меня есть эта функция для подключения приложения, которое я разрабатываю, к другому устройству с поддержкой 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 — это действие, вызывающее этот метод. Я обнаружил, что после вызова метода состояние подключения устройства вообще не меняется, а обратный вызов никогда не вызывается. Мне просто интересно, где это пошло не так?

Спасибо, Боб


person Boyu Fang    schedule 09.09.2013    source источник
comment
Что такое другое устройство BLE?   -  person edoardotognoni    schedule 09.09.2013


Ответы (1)


Не беспокойтесь, на данный момент в API есть ошибка, если вы собираетесь подключиться к классическому устройству BT и двухрежимному устройству BLE, соединение не будет выполнено.

person Boyu Fang    schedule 09.09.2013
comment
Не могли бы вы уточнить? например ссылка на отчет об ошибке была бы хорошей. - person Ifor; 10.09.2013