use of android.bluetooth.BluetoothGatt in project BleLiteLib4android by afunx.
the class BleConnectCompat method createBluetoothGatt.
@TargetApi(Build.VERSION_CODES.M)
private BluetoothGatt createBluetoothGatt(Object iBluetoothGatt, BluetoothDevice remoteDevice) throws IllegalAccessException, InvocationTargetException, InstantiationException {
Constructor bluetoothGattConstructor = BluetoothGatt.class.getDeclaredConstructors()[0];
bluetoothGattConstructor.setAccessible(true);
BleLiteLog.v(TAG, "Found constructor with args count = \" + bluetoothGattConstructor.getParameterTypes().length");
if (bluetoothGattConstructor.getParameterTypes().length == 4) {
return (BluetoothGatt) (bluetoothGattConstructor.newInstance(context, iBluetoothGatt, remoteDevice, TRANSPORT_LE));
} else {
return (BluetoothGatt) (bluetoothGattConstructor.newInstance(context, iBluetoothGatt, remoteDevice));
}
}
use of android.bluetooth.BluetoothGatt in project BleLiteLib4android by afunx.
the class BleGattClientProxyImpl method __close.
private void __close() {
if (!mIsClosed) {
mIsClosed = true;
BleLiteLog.i(TAG, "__close() closing");
// unregister
unregister(BleOperation.BLE_CONNECT);
unregister(BleOperation.BLE_DISCOVER_SERVICE);
unregister(BleOperation.BLE_REQUEST_MTU);
unregister(BleOperation.BLE_READ_CHARACTERISTIC);
unregister(BleOperation.BLE_WRITE_CHARACTERISTIC);
// create operation
final BluetoothGatt bluetoothGatt = getBluetoothGatt();
if (bluetoothGatt == null) {
BleLiteLog.i(TAG, "__close() bluetoothGatt is null");
}
BleCloseOperation closeOperation = BleCloseOperation.createInstance(bluetoothGatt);
// execute operation
closeOperation.doRunnableSelfAsync(false);
BleLiteLog.i(TAG, "__close() closed");
} else {
BleLiteLog.i(TAG, "__close() it is closed already");
}
}
Aggregations