如何在Android中断开蓝牙连接
我正在尝试通过使用断开蓝牙
if (bluetoothAdapter != null) {
if(bluetoothAdapter.isEnabled()|bluetoothAdapter.isDiscovering()){
bluetoothAdapter.disable();
bluetoothAdapter.cancelDiscovery();
}
}
,但它不起作用。任何人都可以提出一些对我来说富有成效的建议。
I am trying to disconnect bluetooth by using
if (bluetoothAdapter != null) {
if(bluetoothAdapter.isEnabled()|bluetoothAdapter.isDiscovering()){
bluetoothAdapter.disable();
bluetoothAdapter.cancelDiscovery();
}
}
But it is not working.Can anyone suggest something on that which will be fruitful for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要断开连接,您应该尝试断开特定连接,而不是关闭蓝牙。关闭蓝牙将导致其他活动连接(您可能还没有创建也断开连接)
如果这是您想要的,即断开所有连接,那么在上面的代码中您应该首先取消发现,然后取消禁用。
要执行这两项操作,您需要 BLUETOOTH_ADMIN 权限。
If you are disconnecting you should try and disconnect your specific connection rather than turning off bluetooth.. turning off will cause other active connections (which you might not have created also to disconnect)
If this is what you want i.e to disconnect every thing, then in the code above you should first cancel Discovery then Disable.
To do both of these you need the BLUETOOTH_ADMIN privilege.