Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

BluetoothConnectionCallback

public interface BluetoothConnectionCallback

com.google.android.things.bluetooth.BluetoothConnectionCallback


This callback is invoked when the device receives requests for Bluetooth profile connections and contains relevant information to handle the connection process.

Summary

Public methods

default void onConnected(BluetoothDevice bluetoothDevice, int profile)

Invoked when a connection for a profile has been established with the remote device.

default void onConnectionRequestCancelled(BluetoothDevice bluetoothDevice, int requestType)

Invoked when a prior connection request notified using onConnectionRequested(BluetoothDevice, ConnectionParams) has been cancelled or timed out.

default void onConnectionRequested(BluetoothDevice bluetoothDevice, ConnectionParams connectionParams)

Invoked when a remote device requests a connection.

default void onDisconnected(BluetoothDevice bluetoothDevice, int profile)

Invoked when a Bluetooth connection for a profile is disconnected from the remote device.

Public methods

onConnected

void onConnected (BluetoothDevice bluetoothDevice, 
                int profile)

Invoked when a connection for a profile has been established with the remote device.

Parameters
bluetoothDevice BluetoothDevice: remote Bluetooth device.

profile int: BluetoothProfile which was connected.

onConnectionRequestCancelled

void onConnectionRequestCancelled (BluetoothDevice bluetoothDevice, 
                int requestType)

Invoked when a prior connection request notified using onConnectionRequested(BluetoothDevice, ConnectionParams) has been cancelled or timed out.

This callback implies that the previous connection request has expired and the connection should be attempted again.

Parameters
bluetoothDevice BluetoothDevice: remote Bluetooth device.

requestType int: Type of access request. One of REQUEST_TYPE_PROFILE_CONNECTION, REQUEST_TYPE_PHONEBOOK_ACCESS, REQUEST_TYPE_MESSAGE_ACCESS, REQUEST_TYPE_SIM_ACCESS

onConnectionRequested

void onConnectionRequested (BluetoothDevice bluetoothDevice, 
                ConnectionParams connectionParams)

Invoked when a remote device requests a connection. The connection can be generic or for specific profile types. It is the responsibility of the calling code to convey this information to the user and obtain consent.

Once the calling code has obtained user consent, they may confirm/deny the connection request using confirmOrDenyConnection(BluetoothDevice, ConnectionParams, boolean).

Parameters
bluetoothDevice BluetoothDevice: remote Bluetooth device.

connectionParams ConnectionParams: Contains all the required information about the connection request.

onDisconnected

void onDisconnected (BluetoothDevice bluetoothDevice, 
                int profile)

Invoked when a Bluetooth connection for a profile is disconnected from the remote device.

Parameters
bluetoothDevice BluetoothDevice: remote Bluetooth device.

profile int: BluetoothProfile which was disconnected.