有没有办法查明非 Android 蓝牙设备是否已连接到我的 Android 设备?
我有一部 Android 手机和一个非 Android 设备,例如蓝牙拨号器。
据我所知,
使用像 ACL_CONNECTED 这样的侦听器,如果蓝牙设备在应用程序运行时连接,我们可以捕获蓝牙设备的连接。
但是,有什么方法可以在应用程序启动之前知道设备是否已连接到手机,并且我的应用程序可以通过它进行连接?
换句话说,
如果在启动应用程序之前设备已连接,我会收到 ACL_CONNECTED
或其他接收器吗?
谢谢。
I have an android phone and a non-android device like a bluetooth dialer with me.
As Far As I Know
With listeners like ACL_CONNECTED
we can catch connecting of a bluetooth device if it's connecting while application is running.
But is there any way to know if a device is connected to phone before the app is started and my app can connect through it?
In Other Words
will I recieve ACL_CONNECTED
or other recievers if the device is already connected before I start my application?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
BroadcastReceiver
在连接设备时接收广播,并使用SharedPreference
存储布尔值等值。这可能是接收器的代码:
您还应该在设备连接后启动一项服务,该服务监视蓝牙是否关闭,然后将
SharedPreference
设置为 false,因为您不会收到 <代码>ACL_DISCONNECT 广播。这可能看起来像这样:
Use a
BroadcastReceiver
to receive the Broadcast when a device is connected and aSharedPreference
to store a value like a Boolean.This could be a code for the Receiver:
You should also start a service once the device is connected, that watches if Bluetooth is turned off and then sets the
SharedPreference
to false, as you would not receive aACL_DISCONNECT
Broadcast.That could look like this: