Android取消发现蓝牙不起作用
我想通过单击按钮来停止蓝牙发现过程。我使用 btAdapter.cancelDiscovery()
,但我的应用程序仍然扫描设备。我已将 BLUETOOTH_ADMIN
权限放入清单中。我在这里错过了什么吗?
编辑:来自 Logcat 的帖子
DEBUG/TAG(2901): stop Discovery
ERROR/BluetoothEventLoop.cpp(98): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/2664/hci0
ERROR/BluetoothService.cpp(98): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
INFO/DTUN_CLNT(2664): Client calling DTUN_METHOD_DM_START_DISCOVERY (id 2)
INFO/(2649): DTUN_ReceiveCtrlMsg: [DTUN] Received message [BTLIF_DTUN_METHOD_CALL] 4354
INFO/(2649): handle_method_call: handle_method_call :: received DTUN_METHOD_DM_START_DISCOVERY (id 2), len 0
I want to stop Bluetooth discovery process by a button click. I use btAdapter.cancelDiscovery()
, but my app still scans for devices. I already put BLUETOOTH_ADMIN
permission in manifest. Do I miss something here?
Edit: Post from Logcat
DEBUG/TAG(2901): stop Discovery
ERROR/BluetoothEventLoop.cpp(98): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/2664/hci0
ERROR/BluetoothService.cpp(98): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
INFO/DTUN_CLNT(2664): Client calling DTUN_METHOD_DM_START_DISCOVERY (id 2)
INFO/(2649): DTUN_ReceiveCtrlMsg: [DTUN] Received message [BTLIF_DTUN_METHOD_CALL] 4354
INFO/(2649): handle_method_call: handle_method_call :: received DTUN_METHOD_DM_START_DISCOVERY (id 2), len 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建一个新项目来测试
cancelDiscovery()
。一旦我们调用此方法,就会广播ACTION_DISCOVERY_FINISHED
。就我而言,我使用处理程序来重复发现过程,因此我也必须停止它。I create a new project to test
cancelDiscovery()
. Once we call this method,ACTION_DISCOVERY_FINISHED
is broadcasted. In my case, I use handler to repeat the discovery process, so I have to stop it as well.