1

I have a Danalock V3 Smart Lock. It's working as advertised, but I want my own Android application to detect whenever I come in-range of this device. So my application needs to be "constantly aware" of whether the device is in-range or not. My question is: is this feasible? If yes, how?

As far as I can tell, the device is not bonded to the phone. If I iterate through the list of bonded devices, it doesn't show:

// example code
for (dev in btAdapter.bondedDevices) {
    val string = "${dev.name}: ${dev.address}"
    println(string) // <-- All my bonded devices are listed, not the Danalock device
}

The device is managed through Danalocks own proprietary app (as mentioned this is working). But it is a Bluetooth device, so I figured I should be able to detect it's presence in my application, somehow.

birgersp
  • 3,909
  • 8
  • 39
  • 79
  • 3
    The danalock most likely uses Bluetooth Low Energy, which requires a proprietary app, instead of Bluetooth Classic, which allows devices to be visible inside your phone's Bluetooth settings. Try to use a generic BLE scanner like [nRF Connect](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-mobile) to find your lock. It probably advertises its presence all the time which would allow you to detect it without connecting to it using your own app and BLE. – Michael Kotzjan Jan 31 '22 at 09:12
  • Great suggestion! I think I found the address of the lock. But now the question is, can my application keep scanning 24/7 without (effectively) draining the battery? – birgersp Jan 31 '22 at 11:16
  • 1
    It will definitely drain your battery, but Bluetooth Low Energy is called that for a reason ;) Your main problem will be the energy-saving measurements on your android device. But since you only develop the app for yourself it will be easier. You usually have to handle different manufacturers and android SDK versions... – Michael Kotzjan Jan 31 '22 at 11:30

1 Answers1

1

This is a bit tricky because theoretically, it should be doable. As Michael Kotzjan said, as long as you know the name of your device (e.g. using nRF Connect), you can continuously scan for this name in the background mode and then as soon as you detect it, you can get a notification in your Android app. The whole BLE beacon technology works like this so it's certainly doable.

Practically, you will be facing a few challenges when it comes to BLE background mode. Since Android P, the OS has an adaptive battery optimisation feature that might kill off some apps in the background. There are a few ways around this but it will not be completely straight-forward. Have a look at the links below which cover the subject in more detail:-

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72