Udostępnij za pośrednictwem


BluetoothGattServer.Connect(BluetoothDevice, Boolean) Method

Definition

Initiate a connection to a Bluetooth GATT capable device.

[Android.Runtime.Register("connect", "(Landroid/bluetooth/BluetoothDevice;Z)Z", "")]
[Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")]
public bool Connect (Android.Bluetooth.BluetoothDevice? device, bool autoConnect);
[<Android.Runtime.Register("connect", "(Landroid/bluetooth/BluetoothDevice;Z)Z", "")>]
[<Android.Runtime.RequiresPermission("android.permission.BLUETOOTH_CONNECT")>]
member this.Connect : Android.Bluetooth.BluetoothDevice * bool -> bool

Parameters

autoConnect
Boolean

Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).

Returns

true, if the connection attempt was initiated successfully

Attributes

Remarks

Initiate a connection to a Bluetooth GATT capable device.

The connection may not be established right away, but will be completed when the remote device is available. A BluetoothGattServerCallback#onConnectionStateChange callback will be invoked when the connection state changes as a result of this function.

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. 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.

Java documentation for android.bluetooth.BluetoothGattServer.connect(android.bluetooth.BluetoothDevice, boolean).

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