I have this function to call connect the application I am developing to another BLE enabled device:
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
is the activity that calling this method. I found that after calling the method the connection state of the device is not changed at all, and the callback is never invoked. I am just wondering where did it go wrong?
Thanks, Bob
不用担心,目前API中存在一个错误,如果您要连接到BT经典和BLE双模设备,则连接将失败。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.