語言

BluetoothDevice.ConnectGatt 方法

定義

多載

名稱 Description
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

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

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 回撥處理程序,將接收非同步回撥。

傳回

屬性

例外狀況

若回調為空

備註

連接由此裝置主機託管的 GATT 伺服器。 來電者是 GATT 客戶端。 回調用於將結果傳送給呼叫者,例如連線狀態以及任何後續的 GATT 用戶端操作。 此方法會回傳一個 BluetoothGatt 實例。 你可以使用 BluetoothGatt 來執行 GATT 用戶端操作。

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

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

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

用於 GATT 連接遠端雙模裝置BluetoothDevice#TRANSPORT_AUTO的首選傳輸方式,或BluetoothDevice#TRANSPORT_BREDRBluetoothDevice#TRANSPORT_LE

傳回

屬性

備註

連接由此裝置主機託管的 GATT 伺服器。 來電者是 GATT 客戶端。 回調用於將結果傳送給呼叫者,例如連線狀態以及任何後續的 GATT 用戶端操作。 此方法會回傳一個 BluetoothGatt 實例。 你可以使用 BluetoothGatt 來執行 GATT 用戶端操作。

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

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

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

用於 GATT 連接遠端雙模裝置BluetoothDevice#TRANSPORT_AUTO的首選傳輸方式,或BluetoothDevice#TRANSPORT_BREDRBluetoothDevice#TRANSPORT_LE

phy
BluetoothPhy

用於遠端 LE 裝置的首選 PHY。 位元順序為 ,BluetoothDevice#PHY_LE_1M_MASK任意 BluetoothDevice#PHY_LE_2M_MASK、 、 BluetoothDevice#PHY_LE_CODED_MASK。 若 autoConnect 設定為 ,此選項不會生效。

傳回

屬性

備註

連接由此裝置主機託管的 GATT 伺服器。 來電者是 GATT 客戶端。 回調用於將結果傳送給呼叫者,例如連線狀態以及任何後續的 GATT 用戶端操作。 此方法會回傳一個 BluetoothGatt 實例。 你可以使用 BluetoothGatt 來執行 GATT 用戶端操作。

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

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

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

傳回

屬性

備註

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

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

用於 GATT 連接遠端雙模裝置BluetoothDevice#TRANSPORT_AUTO的首選傳輸方式,或BluetoothDevice#TRANSPORT_BREDRBluetoothDevice#TRANSPORT_LE

phy
BluetoothPhy

用於遠端 LE 裝置的首選 PHY。 位元為 OR,任意 BluetoothDevice#PHY_LE_1M_MASK、 BluetoothDevice#PHY_LE_2M_MASK和 dBluetoothDevice#PHY_LE_CODED_MASK。 若 autoConnect 設定為 ,此選項不會生效。

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)。

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於

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

傳回

屬性

備註

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於