Automatically connect to paired bluetooth device when in range

后端 未结 3 674
庸人自扰
庸人自扰 2020-12-28 20:04

Goal:

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

3条回答
  •  [愿得一人]
    2020-12-28 20:57

    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.

提交回复
热议问题