Android BLE communication

440
January 30, 2017, at 8:01 PM

I am working on Android application that unlocks door using BLE interface. This code executes once "unlock" button is clicked:

public void connectToBleDeviceAndUnlock(BluetoothAdapter mBluetoothAdapter, final Context ctx,
                                        String lockMac, final String userMac, final int userId,
                                        final boolean door, final boolean elevator, final boolean auto) {
    final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(lockMac);
    this.userMac = userMac;
    this.userId = userId;
    device.connectGatt(ctx, false, new BluetoothGattCallback() {
        @Override
        public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
            gatt.discoverServices();
        }
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status,
                                            int newState) {
            if (newState == BluetoothProfile.STATE_CONNECTED) {
                gatt.readRemoteRssi();
            }
        }
        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
                BluetoothGattService service = gatt.getService(UUID.fromString("...-...-;;;"));
                BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString("...-...-..."));
                byte[] bytes = new byte[8];
                // ... create byte array ...
                characteristic.setValue(bytes);
                gatt.writeCharacteristic(characteristic);
            }
        }
    });
}

So it connects to device, reads remote rssi, discovers service and then write to characteristic every time someone clicks to unlock. I think that it has performance impact so unlock action is delayed sometimes. Is it possible somehow to maintain connection to device and just write into characteristic once "unlock" button is clicked?

Rent Charter Buses Company
READ ALSO
Invisible(not gone) back button in the action bar

Invisible(not gone) back button in the action bar

Question is very simple but solution I have tried so many thingsI want to Invisible the back button on the Action bar Not gone

343
Returning to my activity after intent locks application

Returning to my activity after intent locks application

I have an Android application that launches an intent to use the camera or pick pictures from the galleryThe application is targeted to KitKat and has worked perfectly on devices running up to Marshmallow, but not Android 7

345
Code reusabilty for different applications

Code reusabilty for different applications

I have made some small applicationsI just want to integrate some of the modules of these applications into a single application

324
How to compile and android layout XML into bin using android aapt?

How to compile and android layout XML into bin using android aapt?

Android uses one of its build tool AAPT(Android Asset packaging Tool) to compile and zip resources etc into APKI want to use AAPT to compile just one resource file(xml) and save it in my computer

480