BluetoothDevice.ConnectGatt Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ConnectGatt(BluetoothGattConnectionSettings, IExecutor, BluetoothGattCallback)
Connect to the GATT Server hosted by the given device.
[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
Parameters
- gattConnectionSettings
- BluetoothGattConnectionSettings
BluetoothGattConnectionSettings objects with required
gatt settings for the GATT connection
- executor
- IExecutor
The executor to use for the callback.
- callback
- BluetoothGattCallback
GATT callback handler that will receive asynchronous callbacks.
Returns
A BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client operations.
- Attributes
Remarks
Connect to the GATT Server hosted by the given device. Caller acts as a GATT client. BluetoothGattCallback of BluetoothGattConnectionSettings will deliver results to the Caller, such as connection updates and GATT client operation results. The method returns a BluetoothGatt instance. The application can use BluetoothGatt to conduct GATT client operations. For apps targeting Build.VERSION_CODES.S or or higher, this requires the Manifest.permission.BLUETOOTH_CONNECT permission which can be gained with android.app.Activity.requestPermissions(String[],int). Requires Manifest.permission.BLUETOOTH_CONNECT
Android reference for android.bluetooth.BluetoothDevice.connectGatt.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
ConnectGatt(Context, Boolean, BluetoothGattCallback)
Connect to GATT Server hosted by this device.
[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
Parameters
- context
- Context
An Android context. This compatibility parameter is not read by the API 37.2 implementation.
- autoConnect
- Boolean
Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
- callback
- BluetoothGattCallback
GATT callback handler that will receive asynchronous callbacks.
Returns
A GATT client for this device, or null if the platform cannot create it. Connection results arrive through the callback.
- Attributes
Exceptions
if callback is null
Remarks
Connect to GATT Server hosted by this device. Caller acts as GATT client. The callback is used to deliver results to Caller, such as connection status as well as any further GATT client operations. The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client operations.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports)
Connect to GATT Server hosted by this device.
[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
Parameters
- context
- Context
An Android context. This compatibility parameter is not read by the API 37.2 implementation.
- autoConnect
- Boolean
Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
- callback
- BluetoothGattCallback
GATT callback handler that will receive asynchronous callbacks.
- transport
- BluetoothTransports
preferred transport for GATT connections to remote dual-mode devices BluetoothDevice#TRANSPORT_AUTO or BluetoothDevice#TRANSPORT_BREDR or BluetoothDevice#TRANSPORT_LE
Returns
A GATT client for this device, or null if the platform cannot create it. Connection results arrive through the callback.
- Attributes
Remarks
Connect to GATT Server hosted by this device. Caller acts as GATT client. The callback is used to deliver results to Caller, such as connection status as well as any further GATT client operations. The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client operations.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, BluetoothPhy)
Connect to GATT Server hosted by this device.
[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
Parameters
- context
- Context
An Android context. This compatibility parameter is not read by the API 37.2 implementation.
- autoConnect
- Boolean
Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
- callback
- BluetoothGattCallback
GATT callback handler that will receive asynchronous callbacks.
- transport
- BluetoothTransports
preferred transport for GATT connections to remote dual-mode devices BluetoothDevice#TRANSPORT_AUTO or BluetoothDevice#TRANSPORT_BREDR or BluetoothDevice#TRANSPORT_LE
- phy
- BluetoothPhy
preferred PHY for connections to remote LE device. Bitwise OR of any of BluetoothDevice#PHY_LE_1M_MASK, BluetoothDevice#PHY_LE_2M_MASK, and BluetoothDevice#PHY_LE_CODED_MASK. This option does not take effect if autoConnect is set to true.
Returns
A GATT client for this device, or null if the platform cannot create it. Connection results arrive through the callback.
- Attributes
Remarks
Connect to GATT Server hosted by this device. Caller acts as GATT client. The callback is used to deliver results to Caller, such as connection status as well as any further GATT client operations. The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client operations.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, ScanSettingsPhy)
Caution
This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.
Starts a GATT client connection through the overload that uses BluetoothPhy.
[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
Parameters
- context
- Context
An Android context. This compatibility parameter is not read by the API 37.2 implementation.
- autoConnect
- Boolean
true to request an automatic connection when the remote device becomes available; false to request a direct connection.
- callback
- BluetoothGattCallback
The callback that receives GATT connection and operation results.
- transport
- BluetoothTransports
The transport selection forwarded to the GATT connection settings.
- phy
- ScanSettingsPhy
The LE PHY selection mask. This obsolete managed overload casts the value to BluetoothPhy before forwarding it.
Returns
A GATT client for this device, or null if the platform cannot create it. Connection results arrive through the callback.
- Attributes
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, BluetoothPhy, Handler)
Connect to GATT Server hosted by this device.
[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
Parameters
- context
- Context
An Android context. This compatibility parameter is not read by the API 37.2 implementation.
- autoConnect
- Boolean
Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
- callback
- BluetoothGattCallback
GATT callback handler that will receive asynchronous callbacks.
- transport
- BluetoothTransports
preferred transport for GATT connections to remote dual-mode devices BluetoothDevice#TRANSPORT_AUTO or BluetoothDevice#TRANSPORT_BREDR or BluetoothDevice#TRANSPORT_LE
- phy
- BluetoothPhy
preferred PHY for connections to remote LE device. Bitwise OR of any of BluetoothDevice#PHY_LE_1M_MASK, BluetoothDevice#PHY_LE_2M_MASK, an dBluetoothDevice#PHY_LE_CODED_MASK. This option does not take effect if autoConnect is set to true.
- handler
- Handler
The handler to use for the callback. If null, callbacks will happen on
an un-specified background thread.
Returns
A GATT client for this device, or null if the platform cannot create it. Connection results arrive through the callback.
- Attributes
Remarks
Connect to GATT Server hosted by this device. Caller acts as GATT client. The callback is used to deliver results to Caller, such as connection status as well as any further GATT client operations. The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client operations.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
ConnectGatt(Context, Boolean, BluetoothGattCallback, BluetoothTransports, ScanSettingsPhy, Handler)
Caution
This method has the wrong enumeration. Use the version that takes an 'Android.Bluetooth.BluetoothPhy' instead.
Starts a GATT client connection through the overload that uses BluetoothPhy.
[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
Parameters
- context
- Context
An Android context. This compatibility parameter is not read by the API 37.2 implementation.
- autoConnect
- Boolean
true to request an automatic connection when the remote device becomes available; false to request a direct connection.
- callback
- BluetoothGattCallback
The callback that receives GATT connection and operation results.
- transport
- BluetoothTransports
The transport selection forwarded to the GATT connection settings.
- phy
- ScanSettingsPhy
The LE PHY selection mask. This obsolete managed overload casts the value to BluetoothPhy before forwarding it.
- handler
- Handler
The handler used to dispatch GATT callbacks, or null for the platform's default dispatch.
Returns
A GATT client for this device, or null if the platform cannot create it. Connection results arrive through the callback.
- Attributes
Remarks
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.