Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically connect to paired bluetooth device when in range

Goal:

I'm trying to get my android service to auto-connect to an already paired bluetooth device when its in range.

Example:

I have my iphone paired to my car. When I sit down in my car music starts automatically playing. I don't need to connect it again. I don't need to start a song. It just launches itunes and starts playing music. I want this kind of connectivity in my Android application.

One obvious solution is to have a thread running in a background services that tries to connect every X seconds. This however is not optimal due to the toll on battery life.

I tried setting up broadcast receivers to get triggered on ACTION_ACL_CONNECTED but this seems to only get called after I connect to the device.

Is there no way my app can get a notification when the phone walks into range of the device?

I've spent the better part of the last two days trying to get this to work with no luck. There are a billion tutorials on how to connect to a bt device but none to auto connect when in range. Starting to question if this even possible.. I'll be blown away if its not :(

related questions:

Find already paired bluetooth devices automatically, when they are in range

like image 691
Mahir Avatar asked Oct 26 '14 02:10

Mahir


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*.

How does Bluetooth Auto Connect work?

This means if you've already had your smartphone connected to the speaker, it will pair when you walk back into the room provided the speaker source is set to Bluetooth, and Bluetooth is enabled on your phone. Auto pairing will only remember the last device connected.

How do I get my Bluetooth headset to connect automatically to my laptop?

Type services. msc and scroll down to Bluetooth Support Service in the list. Right click on it and select Properties. Set up Start up type to Automatic from the dropdown list.

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.


1 Answers

As mentioned before, there’s no easy way to do that with Bluetooth Classic other than by constantly scanning.

The car radio scenario you mentioned, however, works with some car radios—mine automatically establishes a Bluetooth connection with my phone as soon as I turn the radio on. I have observed similar behavior with Bluetooth keyboards.

I can only speculate that these peripherals periodically try to connect to paired devices until it is sucessful. This makes sense for a peripheral in certain conditions:

  • Draining the battery isn’t a concern. (The radio runs off a car battery, and most of the time it is on, the engine is running and the battery gets charged.)
  • The peripheral talks to only one phone at a time, and can thus suspend its scans while it is connected to one. (This particular radio can only handle one phone at a time.)
  • The peripheral is mostly useless when not connected to another device, and can thus be expected to be connected to something for most of the time it is powered on. (This goes for headsets, keyboards, mice and the like.)

Obviously, that depends on your ability to influence the behavior of the paired device. If it’s an off-the-shelf device, it either works or it doesn’t—but if you’re designing a custom peripheral, it’s worth considering.

like image 145
user149408 Avatar answered Sep 20 '22 08:09

user149408