在Android的蓝牙4.0 API的close()和断开()之间的区别? [英] Difference between close() and disconnect() in Android Bluetooth 4.0 API?

查看:3117
本文介绍了在Android的蓝牙4.0 API的close()和断开()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的蓝牙低耗能的API实现1方法连接到该设备 connectGatt()但2的方法来关闭连接断开连接()关闭()

Android Bluetooth Low Energy API implements 1 method to connect to the device connectGatt() but 2 methods to close the connection disconnect() and close().

文件说:

  • 断开连接():断开已建立的连接,或取消连接尝试    目前正在进行中。

  • disconnect(): Disconnects an established connection, or cancels a connection attempt currently in progress.

关闭():应用程序应尽早调用此方法后,它与完成      这GATT客户端。

close(): Application should call this method as early as possible after it is done with this GATT client.

的<一个源$ C ​​$ C href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothGatt.java">BluetoothGatt.java表明关闭()注销申请和断开()断开客户端。然而,它并没有说什么实际意义。我的意思是,如果只有1路连接到客户端,为什么有2种方式来关闭/断开连接?

The source code of BluetoothGatt.java shows that close() unregisters the application and disconnect() disconnect the client. However it does not say what that actually means. I mean, if there is only 1 way to connect to the client, why there are 2 ways to close/disconnect the connection?

推荐答案

通过断开连接()您可以稍后致电连接()并继续这一循环。

With disconnect() you can later call connect() and continue with that cycle.

在你调用关闭()你做。如果你想再次连接,你将不得不调用 connectGatt() BluetoothDevice类试; 关闭()将释放由 BluetoothGatt持有的任何资源

Once you call close() you are done. If you want to connect again you will have to call connectGatt() on the BluetoothDevice again; close() will release any resources held by BluetoothGatt.

这篇关于在Android的蓝牙4.0 API的close()和断开()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆