简体   繁体   English

Android 的蓝牙`autoConnect` 参数究竟有什么作用?

[英]What exactly does Android's Bluetooth `autoConnect` parameter do?

See BluetoothDevice.connectGatt() .请参阅BluetoothDevice.connectGatt() The description of autoConnect is的描述autoConnect

boolean: Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).布尔值:是直接连接到远程设备(false)还是在远程设备可用时自动连接(true)。

What exactly does this do?这究竟是做什么的? If it is false I suppose it must scan for the specific device for a short time, and give up if it is not found.如果它是false我想它必须在短时间内扫描特定设备,如果找不到就放弃。 But if it is true what does it do?但如果它是true ,它有什么作用呢? Does it start scanning immediately?它会立即开始扫描吗? Does it scan forever?它会永远扫描吗? Does it scan periodically?是否定期扫描? If it disconnects does it automatically reconnect?如果它断开连接会自动重新连接吗? When is Google going to start writing decent documentation? Google 什么时候开始编写像样的文档?

Edit : I have traced the parameter to bt_gatt_client.h :编辑:我已将参数跟踪到bt_gatt_client.h

/** Create a connection to a remote LE or dual-mode device */
bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
                       bool is_direct, int transport);

And a search for is_direct turns up some interesting results. 搜索is_direct会出现一些有趣的结果。

Here is a slightly longer explanation, but it still doesn't answer any questions.这是一个稍长的解释,但它仍然没有回答任何问题。

The autoConnect parameter determines whether to actively connect to the remote device, or rather passively scan and finalize the connection when the remote device is in range/available. autoConnect 参数确定是主动连接到远程设备,还是被动扫描并在远程设备在范围内/可用时完成连接。 Generally, the first ever connection to a device should be direct (autoConnect set to false) and subsequent connections to known devices should be invoked with the autoConnect parameter set to true.通常,与设备的第一次连接应该是直接的(autoConnect 设置为 false),并且应该在将 autoConnect 参数设置为 true 的情况下调用与已知设备的后续连接。

I also found this definition of the Android 5 Bluetooth HCI requirements which contains many useful details, but still no real answer about how autoconnect is supposed to work.我还发现了 Android 5 蓝牙 HCI 要求的这个定义,其中包含许多有用的细节,但仍然没有关于自动连接应该如何工作的真正答案。

More details here on stack overflow: Which correct flag of autoConnect in connectGatt of BLE?有关堆栈溢出的更多详细信息: BLE 的 connectGatt 中 autoConnect 的哪个正确标志?

There are a few non-documented differences between direct and auto connect:直接连接和自动连接之间存在一些未记录在案的差异:

Direct connect is a connection attempt with a 30 seconds timeout.直接连接是具有 30 秒超时的连接尝试。 It will suspend all current auto connects while the direct connect is in progress.当直接连接正在进行时,它将暂停所有当前的自动连接。 If there already is a direct connect pending, the last direct connect will not be executed immediately but rather be queued up and start when the previous has finished.如果已经有一个直接连接挂起,则最后一个直接连接不会立即执行,而是排队并在前一个完成时开始。

With auto connect you can have multiple pending connections at the same time and they will never time out (until explicitly aborted or until Bluetooth is turned off).使用自动连接,您可以同时拥有多个挂起的连接,它们永远不会超时(直到明确中止或蓝牙关闭)。

If the connection was established through an auto connect, Android will automatically try to reconnect to the remote device when it gets disconnected until you manually call disconnect() or close().如果连接是通过自动连接建立的,当远程设备断开连接时,Android 将自动尝试重新连接到远程设备,直到您手动调用 disconnect() 或 close()。 Once a connection established through direct connect disconnects, no attempt is made to reconnect to the remote device.一旦通过直接连接建立的连接断开,就不会尝试重新连接到远程设备。

Direct connect has a different scan interval and scan window at a higher duty than auto connect, meaning it will dedicate more radio time to listen for connectable advertisements for the remote device, ie the connection will be established faster.与自动连接相比,直接连接具有不同的扫描间隔和扫描窗口,其占空比更高,这意味着它将投入更多的无线电时间来侦听远程设备的可连接广告,即连接建立得更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android的@hide注释究竟做了什么? - What exactly does Android's @hide annotation do? 导出Android应用程序到底有什么作用? - What does exporting an Android application do, exactly? 如何使BLE自动连接到android手机的蓝牙而不配对 - how to make BLE autoconnect to Bluetooth of android phone without pairing Android的PatternPathMotion,它的作用是什么?如何使用它? - PatternPathMotion Android, What exactly does it do and how do I use it? android:screenOrientation 在 AndroidManifest.xml 中到底做了什么? - What exactly does android:screenOrientation do in the AndroidManifest.xml? android:layout_column究竟做了什么? - What exactly does android:layout_column do? 每个对象在Quickblox Android私人聊天中的功能是什么? - What does each object do exactly in Quickblox Android Private Chat? AlarmManager.ELAPSED_REALTIME_WAKEUP 在 android 中究竟做了什么 - What does exactly AlarmManager.ELAPSED_REALTIME_WAKEUP do in android 注释在编译时在Android中到底有什么作用? - What does the annotations do exactly in Android at compile time? offsetLeftAndRight()究竟做了什么? - What does offsetLeftAndRight() exactly do?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM