Hi this may sound as a stupid question.But I was unable to find any answers for this, thus posting here.
I am building an indoor application which continuously scans the bluetooth dongles located at different locations in a place like a mall or library.As I move in the mall with android phone in my hand I should be able to get the nearest dongle which I can connect to(Stupid Idea but I want to do something else with this).For this I should be able to continuously scan for the bluetooth devices.
Please can someone tell me how do I make android scan the available Bluetooth devices periodically.
As stated in the documentation device discovery is a lofty process that will directly degrade the performance of any bonds you have with other devices.
With this in mind (error handling omitted):
Your code snippet should work - Only that it will be expensive in terms of power draw and will certainly kill your device/phone in a few hours. The startDiscovery() does a 2 step process, finding the device by inquiring for it and followed by a name discovery ie paging and connecting to the device,
Unfortunately Android does not provide any API to control this and do only inquiry , also there is a periodic inquiry feature defined and supported by most Bluetooth chipsets, Android currently does not have any API to do periodic inquiry which could have been more ideal for your use case.
I guess this was so simple but didnt strike me before. Here is the answer,
Thus we should start discovery again on
ACTION_DISCOVERY_FINISHED
which will continuously scan for devices every 12 seconds.Here is the Code to get the list of all Active Bluetooth Devices[Paired or non-paired]
I get the idea from API demo, i hope this could be useful for all developers.