Search in sources :

Example 11 with BluetoothGatt

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));
    }
}
Also used : Constructor(java.lang.reflect.Constructor) BluetoothGatt(android.bluetooth.BluetoothGatt) TargetApi(android.annotation.TargetApi)

Example 12 with BluetoothGatt

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");
    }
}
Also used : BluetoothGatt(android.bluetooth.BluetoothGatt) BleCloseOperation(com.afunx.ble.blelitelib.operation.BleCloseOperation)

Aggregations

BluetoothGatt (android.bluetooth.BluetoothGatt)12 BluetoothGattService (android.bluetooth.BluetoothGattService)2 TargetApi (android.annotation.TargetApi)1 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 BluetoothDevice (android.bluetooth.BluetoothDevice)1 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)1 BluetoothGattDescriptor (android.bluetooth.BluetoothGattDescriptor)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 BleCloseOperation (com.afunx.ble.blelitelib.operation.BleCloseOperation)1 BleReadCharacteristicOperation (com.afunx.ble.blelitelib.operation.BleReadCharacteristicOperation)1 BleRequestMtuOperation (com.afunx.ble.blelitelib.operation.BleRequestMtuOperation)1 BleWriteCharacteristicOperation (com.afunx.ble.blelitelib.operation.BleWriteCharacteristicOperation)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1 BtLEAction (nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction)1 ConditionalWriteAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction)1 WriteAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction)1