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.