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

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

问题描述

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

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.

的close():它与完成后的应用应尽可能早地调用此方法
     这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表明close()方法注销申请和断开()断开客户端。然而,它并没有说什么实际意义。我的意思是,如果只有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.

一旦你调用的close()你做。如果你想再次连接,你将不得不调用 connectGatt() BluetoothDevice类再度; 的close()将释放由 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的蓝牙API的close()和断开()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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