Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Is it possible to automatically connect to Bluetooth LE device when it comes in range and starts advertising ?

I'm looking for a way to automatically connect Android device to a Bluetooth LE (4.0 Smart) device when it comes in range (and starts advertising). I expect it to work like a Bluetooth headphones - when turned on they automatically connect to a paired phone (if it is in range).

I thought about running a Service in background that will periodically (every 50-100ms) check for advertisement. However one of the main concerns is battery life of Android device.

Could someone please advice what would be the best way to implement such functionality on Android 4.3 and up ?

Thanks in advance!

like image 830
user2995035 Avatar asked Nov 15 '13 06:11

user2995035


People also ask

How do I make Bluetooth connect automatically?

A headset or a speaker doesn't reconnect automaticallyReturn to Settings, search for Bluetooth auto-connect and enable this feature. Make sure that the other device is within the effective Bluetooth range from your smartphone and restart it. Re-enable Bluetooth on the phone and check if the issue is fixed*.

Does Bluetooth automatically connect to other devices?

You can use Bluetooth to connect some devices to your phone without a cord. After you pair a Bluetooth device for the first time, your devices can pair automatically.

Does Android Auto automatically turn on Bluetooth?

This is also why turning off Bluetooth on either device will prevent the connection. You can't stop Android Auto from turning on Bluetooth because it's a necessary function of the system.


2 Answers

set autoConnect parameter in connectGatt() to true. (second parameter)

like image 175
user3698465 Avatar answered Oct 22 '22 17:10

user3698465


You can register a broadcast receiver to receive broadcasts when a Bluetooth device is found. See the API guide topic Bluetooth for details and sample code.

Also look at the topic Bluetooth Low Energy.

Finally, take a look at this thread, which is basically the same question.

like image 1
Ted Hopp Avatar answered Oct 22 '22 18:10

Ted Hopp