2

As question suggested we have our own BLE device and Android app to connect with that device. We are able to connect with BLE device and do all operations successfully.

In the meantime, we are able to detect our BLE device with other 3rd party apps and able to connect and do operations.

But we want to restrict the other apps to connect with our BLE device and if they connect with device immediately it needs to disconnect. I have searched in google and SO but unable to get any information to achieve this, if any one have idea help me out

YBDevi
  • 439
  • 5
  • 22
  • you can send some secret data to the device to verify that it is your app, e. g. authorize – Vladyslav Matviienko Feb 13 '19 at 12:56
  • @VladyslavMatviienko can you please elaborate a little bit more, I'm new to this topic, if you have any articles regarding this post here it will help me a lot. – YBDevi Feb 13 '19 at 12:59
  • 1
    I don't have articles. Depending on how you are going to communicate with device, you need to tell the device some secret string. The device will check if it is correct (matches the one it expects), and only then it will continue communication. If the string is wrong, or not sent during some period of time, then device should just disconnect.\ – Vladyslav Matviienko Feb 13 '19 at 13:02

1 Answers1

2

on connect event send some data from app to the device and get verified data from device to app, change some programmed mechanism that app send some data to device and device verify and gives acknowledgement and based on that you keep connections or else you can disconnect from the device. I had implemented this things and working perfectly

public boolean connectDeviceBonded(String address, String name) {
        if (address == null) {
            throw new NullPointerException("Address cannot be null or not found");
        }
        macAddress = address;


        boolean value =  bluetoothLe.connectScannerBonded(address);
        if ( value) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            int ret = reqEncryptedKey(10000);
            if (ret != SUCCESS){
                return false;
            }
        }
        return value;
    }

reqEncryptedKey() send some encrypted data to device and device has same encryption algorithm and device verify my data and gives response to app the success and fail, based on success and fail app can keep connection and disconnect. and I also put some piece of code in device so that if device is giving fail then device disconnects automatically.

Dharmeet Soni
  • 204
  • 1
  • 7