BluetoothDevice.Connect 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.
Connects all user enabled and supported bluetooth profiles between the local and remote device.
[Android.Runtime.Register("connect", "()I", "", ApiSince=37)]
public int Connect();
[<Android.Runtime.Register("connect", "()I", "", ApiSince=37)>]
member this.Connect : unit -> int
Returns
BluetoothStatusCodes#SUCCESS upon successful initiation of the operation,
otherwise an error code.
- Attributes
Remarks
Connects all user enabled and supported bluetooth profiles between the local and remote device. If no profiles are user enabled (e.g. first connection), we connect all supported profiles. If the device is not already connected, this will page the device before initiating profile connections. Connection is asynchronous and you should listen to each profile's broadcast intent ACTION_CONNECTION_STATE_CHANGED to verify whether connection was successful. For example, to verify a2dp is connected, you would listen for BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED
This method requires the calling app to have the Manifest.permission.BLUETOOTH_CONNECT permission. Additionally, an app must either have Manifest.permission.BLUETOOTH_PRIVILEGED permission or be associated with the Companion Device manager (see android.companion.CompanionDeviceManager.associate(AssociationRequest,android.companion.CompanionDeviceManager.Callback,Handler)). 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).
Android reference for android.bluetooth.BluetoothDevice.connect.
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.