广播如果一个蓝牙设备连接/断开? [英] Broadcast if a bluetooth device is connecting/disconnecting?
问题描述
我想开始一种服务,当特定BluetoothDevice类连接,并停止该服务时,它的断开。 很显然,我不希望有一个后台服务,如果一个蓝牙设备连接,就是始终检查,所以我想用一个接收器来实现这一点。
这是实际可能吗? android.bluetooth.device.action.ACL_CONNECTED
中提到<一个href="http://stackoverflow.com/questions/4510500/android-bluetooth-device-connected-broadcast">here,但显然没有奏效。
谢谢!
&LT;意向滤光器&gt; &lt;作用机器人:名称=android.bluetooth.device.action.ACL_CONNECTED/&GT;
&lt;作用机器人:名称=android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED/&GT;
&lt;作用机器人:名称=android.bluetooth.device.action.ACL_DISCONNECTED/&GT;
&所述; /意图滤光器&gt;
这些都是你必须与你的撒施接收器添加过滤器。
ACL_CONNECTED
信号,蓝牙连接,当 ACL_DISCONNECTED
蓝牙信号断线
有关你必须检查的意图/背景广播接收器专用设备
两个权限你要广告是
&LT;使用-权限的Android:名称=android.permission.BLUETOOTH_ADMIN/&GT;
&LT;使用-权限的Android:名称=android.permission.BLUETOOTH/&GT;
使用此我想,这一定解决你的问题。
I want start a service, when a specific bluetoothdevice is connected and stop this service when it's disconnected. Obviously I don't want to have a background service that is always checking if a BT device is connected, so I want to achieve this with a Receiver.
Is this actually possible? android.bluetooth.device.action.ACL_CONNECTED
is mentioned here, but apparently it didn't work.
Thanks!
<intent-filter> <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
These are the filters you have to add with your broad cast receiver.
ACL_CONNECTED
signals when bluetooth is connected and ACL_DISCONNECTED
signals bluetooth disconnection
For specific device you have to check intents/context in broadcast receiver
Two permission you have to ad are
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
Use this I think this must solve your problem
这篇关于广播如果一个蓝牙设备连接/断开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!