语言

BluetoothDevice.ConnectGatt 方法

定义

重载

名称 说明
ConnectGatt(BluetoothGattConnectionSettings, IExecutor, BluetoothGattCallback)

连接到由给定设备托管的 GATT 服务器。

ConnectGatt(Context, Boolean, BluetoothGattCallback)

连接到此设备托管的 GATT 服务器。

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports)

连接到此设备托管的 GATT 服务器。

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, BluetoothPhy)

连接到此设备托管的 GATT 服务器。

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, ScanSettingsPhy)
已过时.
ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, BluetoothPhy, Handler)

连接到此设备托管的 GATT 服务器。

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, ScanSettingsPhy, Handler)
已过时.

ConnectGatt(BluetoothGattConnectionSettings, IExecutor, BluetoothGattCallback)

连接到由给定设备托管的 GATT 服务器。

[Android.Runtime.Register("connectGatt", "(Landroid/bluetooth/BluetoothGattConnectionSettings;Ljava/util/concurrent/Executor;Landroid/bluetooth/BluetoothGattCallback;)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=37)]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")]
public Android.Bluetooth.BluetoothGatt? ConnectGatt(Android.Bluetooth.BluetoothGattConnectionSettings gattConnectionSettings, Java.Util.Concurrent.IExecutor executor, Android.Bluetooth.BluetoothGattCallback callback);
[<Android.Runtime.Register("connectGatt", "(Landroid/bluetooth/BluetoothGattConnectionSettings;Ljava/util/concurrent/Executor;Landroid/bluetooth/BluetoothGattCallback;)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=37)>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")>]
member this.ConnectGatt : Android.Bluetooth.BluetoothGattConnectionSettings * Java.Util.Concurrent.IExecutor * Android.Bluetooth.BluetoothGattCallback -> Android.Bluetooth.BluetoothGatt

参数

gattConnectionSettings
BluetoothGattConnectionSettings

BluetoothGattConnectionSettings 具有 GATT 连接的必需 gatt 设置的对象

executor
IExecutor

要用于回调的执行程序。

callback
BluetoothGattCallback

将接收异步回调的 GATT 回调处理程序。

返回

BluetoothGatt 实例。 可以使用 BluetoothGatt 执行 GATT 客户端操作。

特性

注解

连接到由给定设备托管的 GATT 服务器。 调用方充当 GATT 客户端。 BluetoothGattConnectionSettings 的 BluetoothGattCallback 将结果传递到调用方,例如连接更新和 GATT 客户端操作结果。 该方法返回 BluetoothGatt 实例。 应用程序可以使用 BluetoothGatt 执行 GATT 客户端操作。 对于面向Build.VERSION_CODES的应用。S 或更高版本,这需要Manifest.permission.BLUETOOTH_CONNECT权限,android.app.Activity.requestPermissions(String[],int) 获得的权限。 需要Manifest.permission.BLUETOOTH_CONNECT

Android 参考。android.bluetooth.BluetoothDevice.connectGatt

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

ConnectGatt(Context, Boolean, BluetoothGattCallback)

连接到此设备托管的 GATT 服务器。

[Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;)Landroid/bluetooth/BluetoothGatt;", "")]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")]
public Android.Bluetooth.BluetoothGatt? ConnectGatt(Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? callback);
[<Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;)Landroid/bluetooth/BluetoothGatt;", "")>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")>]
member this.ConnectGatt : Android.Content.Context * bool * Android.Bluetooth.BluetoothGattCallback -> Android.Bluetooth.BluetoothGatt

参数

context
Context
autoConnect
Boolean

是直接连接到远程设备(false),还是一旦远程设备可用(true)即可自动连接。

callback
BluetoothGattCallback

将接收异步回调的 GATT 回调处理程序。

返回

特性

例外

如果回调为 null,则为

注解

连接到此设备托管的 GATT 服务器。 调用方充当 GATT 客户端。 回调用于将结果传递到调用方,例如连接状态以及任何其他 GATT 客户端操作。 该方法返回 BluetoothGatt 实例。 可以使用 BluetoothGatt 执行 GATT 客户端操作。

Java文档android.bluetooth.BluetoothDevice.connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports)

连接到此设备托管的 GATT 服务器。

[Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;I)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=23)]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")]
public Android.Bluetooth.BluetoothGatt? ConnectGatt(Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? callback, Android.Bluetooth.BluetoothTransports transport);
[<Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;I)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=23)>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")>]
member this.ConnectGatt : Android.Content.Context * bool * Android.Bluetooth.BluetoothGattCallback * Android.Bluetooth.BluetoothTransports -> Android.Bluetooth.BluetoothGatt

参数

context
Context
autoConnect
Boolean

是直接连接到远程设备(false),还是一旦远程设备可用(true)即可自动连接。

callback
BluetoothGattCallback

将接收异步回调的 GATT 回调处理程序。

transport
BluetoothTransports

与远程双模式设备BluetoothDevice#TRANSPORT_AUTOBluetoothDevice#TRANSPORT_BREDR或或BluetoothDevice#TRANSPORT_LE

返回

特性

注解

连接到此设备托管的 GATT 服务器。 调用方充当 GATT 客户端。 回调用于将结果传递到调用方,例如连接状态以及任何其他 GATT 客户端操作。 该方法返回 BluetoothGatt 实例。 可以使用 BluetoothGatt 执行 GATT 客户端操作。

Java文档android.bluetooth.BluetoothDevice.connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, BluetoothPhy)

连接到此设备托管的 GATT 服务器。

[Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;II)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=26)]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")]
public Android.Bluetooth.BluetoothGatt? ConnectGatt(Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? callback, Android.Bluetooth.BluetoothTransports transport, Android.Bluetooth.BluetoothPhy phy);
[<Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;II)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=26)>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")>]
member this.ConnectGatt : Android.Content.Context * bool * Android.Bluetooth.BluetoothGattCallback * Android.Bluetooth.BluetoothTransports * Android.Bluetooth.BluetoothPhy -> Android.Bluetooth.BluetoothGatt

参数

context
Context
autoConnect
Boolean

是直接连接到远程设备(false),还是一旦远程设备可用(true)即可自动连接。

callback
BluetoothGattCallback

将接收异步回调的 GATT 回调处理程序。

transport
BluetoothTransports

与远程双模式设备BluetoothDevice#TRANSPORT_AUTOBluetoothDevice#TRANSPORT_BREDR或或BluetoothDevice#TRANSPORT_LE

phy
BluetoothPhy

用于连接到远程 LE 设备的首选 PHY。 任何BluetoothDevice#PHY_LE_1M_MASKBluetoothDevice#PHY_LE_2M_MASK项的按位 OR,以及BluetoothDevice#PHY_LE_CODED_MASK。 如果 autoConnect 设置为 true,则此选项不会生效。

返回

特性

注解

连接到此设备托管的 GATT 服务器。 调用方充当 GATT 客户端。 回调用于将结果传递到调用方,例如连接状态以及任何其他 GATT 客户端操作。 该方法返回 BluetoothGatt 实例。 可以使用 BluetoothGatt 执行 GATT 客户端操作。

Java文档android.bluetooth.BluetoothDevice.connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int, int)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, ScanSettingsPhy)

注意

This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.

[System.Obsolete("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")]
public Android.Bluetooth.BluetoothGatt? ConnectGatt(Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? callback, Android.Bluetooth.BluetoothTransports transport, Android.Bluetooth.LE.ScanSettingsPhy phy);
[<System.Obsolete("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")>]
member this.ConnectGatt : Android.Content.Context * bool * Android.Bluetooth.BluetoothGattCallback * Android.Bluetooth.BluetoothTransports * Android.Bluetooth.LE.ScanSettingsPhy -> Android.Bluetooth.BluetoothGatt

参数

context
Context
autoConnect
Boolean

返回

特性

注解

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, BluetoothPhy, Handler)

连接到此设备托管的 GATT 服务器。

[Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;IILandroid/os/Handler;)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=26)]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")]
public Android.Bluetooth.BluetoothGatt? ConnectGatt(Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? callback, Android.Bluetooth.BluetoothTransports transport, Android.Bluetooth.BluetoothPhy phy, Android.OS.Handler? handler);
[<Android.Runtime.Register("connectGatt", "(Landroid/content/Context;ZLandroid/bluetooth/BluetoothGattCallback;IILandroid/os/Handler;)Landroid/bluetooth/BluetoothGatt;", "", ApiSince=26)>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")>]
member this.ConnectGatt : Android.Content.Context * bool * Android.Bluetooth.BluetoothGattCallback * Android.Bluetooth.BluetoothTransports * Android.Bluetooth.BluetoothPhy * Android.OS.Handler -> Android.Bluetooth.BluetoothGatt

参数

context
Context
autoConnect
Boolean

是直接连接到远程设备(false),还是一旦远程设备可用(true)即可自动连接。

callback
BluetoothGattCallback

将接收异步回调的 GATT 回调处理程序。

transport
BluetoothTransports

与远程双模式设备BluetoothDevice#TRANSPORT_AUTOBluetoothDevice#TRANSPORT_BREDR或或BluetoothDevice#TRANSPORT_LE

phy
BluetoothPhy

用于连接到远程 LE 设备的首选 PHY。 任一BluetoothDevice#PHY_LE_1M_MASKBluetoothDevice#PHY_LE_2M_MASK的按位 OR,即 dBluetoothDevice#PHY_LE_CODED_MASK。 如果 autoConnect 设置为 true,则此选项不会生效。

handler
Handler

要用于回调的处理程序。 如果 null出现,则回调将在未指定的后台线程上发生。

返回

特性

注解

连接到此设备托管的 GATT 服务器。 调用方充当 GATT 客户端。 回调用于将结果传递到调用方,例如连接状态以及任何其他 GATT 客户端操作。 该方法返回 BluetoothGatt 实例。 可以使用 BluetoothGatt 执行 GATT 客户端操作。

Java文档android.bluetooth.BluetoothDevice.connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback, int, int, android.os.Handler)。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于

ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, ScanSettingsPhy, Handler)

注意

This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.

[System.Obsolete("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")]
public Android.Bluetooth.BluetoothGatt? ConnectGatt(Android.Content.Context? context, bool autoConnect, Android.Bluetooth.BluetoothGattCallback? callback, Android.Bluetooth.BluetoothTransports transport, Android.Bluetooth.LE.ScanSettingsPhy phy, Android.OS.Handler? handler);
[<System.Obsolete("This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.")>]
member this.ConnectGatt : Android.Content.Context * bool * Android.Bluetooth.BluetoothGattCallback * Android.Bluetooth.BluetoothTransports * Android.Bluetooth.LE.ScanSettingsPhy * Android.OS.Handler -> Android.Bluetooth.BluetoothGatt

参数

context
Context
autoConnect
Boolean
handler
Handler

返回

特性

注解

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于