How to detect if bluetooth device is connected

前端 未结 5 1181
春和景丽
春和景丽 2020-12-28 23:51

In android how can my Activity will get to know if a Bluetooth A2DP device is connected to my device.
Is there any broadcast receiver for that?
How to write this bro

5条回答
  •  不思量自难忘°
    2020-12-29 00:52

    You cannot get the list of connected devices by calling any API. You need instead to listen to the intents ACTION_ACL_CONNECTED, ACTION_ACL_DISCONNECTED that notifies about devices being connected or disconnected. No way to get the initial list of connected devices.

    I had this problem in my app and the way I handle it (didn't find better...) is to bounce off/on the Bluetooth at application start to be sure to start with an empty list of connected devices, and then listen to the above intents.

提交回复
热议问题