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
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*.
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.
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With