public class BluetoothDevice
extends java.lang.Object
BluetoothDevice
class represents a remote Bluetooth device.
Devices may be retrieved from the Bluetooth adapter by scanning
or
advertising
.
This class provides methods to get information on the remote device. It also allows to manage the connection with this device, to manage pairing and to discover the services that the device provides.
Modifier and Type | Method and Description |
---|---|
boolean |
connect(ConnectionCallbacks connectionCallbacks)
Initiates connection with this device.
|
boolean |
disconnect()
Initiates disconnection with this device.
|
boolean |
discoverServices()
Initiates the discovery of the services provided by this device.
|
BluetoothService |
findService(BluetoothUuid serviceUuid)
Returns the service with the given UUID.
|
java.lang.String |
getAddress()
Returns the Bluetooth address of this device.
|
BluetoothService[] |
getServices()
Returns the list of services provided by this device.
|
boolean |
isConnected()
Returns whether the adapter is currently connected to this device.
|
boolean |
pair()
Initiates pairing with this device.
|
boolean |
pairReply(boolean accept)
Replies to the pairing request of this device.
|
boolean |
passkeyReply(boolean accept,
int passkey)
Replies to the passkey request of this device.
|
public java.lang.String getAddress()
public BluetoothService[] getServices()
This method does not perform a services discovery and only returns the services which have been found earlier by
discovering services
. If the adapter is not connected to this device or if the services
of this device have not been discovered so far, an empty list will be returned.
The GATT events related to these services may be handled by setting
the client callbacks
.
findService(BluetoothUuid)
public BluetoothService findService(BluetoothUuid serviceUuid)
This method is equivalent of looking up the service with the given UUID in the list returned by
getServices()
.
The GATT events related to this service may be handled by setting the
client callbacks
.
serviceUuid
- the UUID of the service to look for.getServices()
public boolean connect(ConnectionCallbacks connectionCallbacks)
The connectionCallbacks object will receive the connection events.
connectionCallbacks
- the object which will receive the connection events.ConnectionCallbacks.onConnectFailed(BluetoothDevice)
,
ConnectionCallbacks.onConnected(BluetoothDevice)
public boolean disconnect()
ConnectionCallbacks.onDisconnected(BluetoothDevice)
public boolean isConnected()
public boolean pair()
This operation may only be performed while connected to this device.
ConnectionCallbacks.onPairCompleted(BluetoothDevice, boolean)
,
ConnectionCallbacks.onPasskeyRequest(BluetoothDevice)
public boolean pairReply(boolean accept)
This operation may only be performed after received a pairing request.
accept
- true if the pairing request should be accepted, false otherwise.ConnectionCallbacks.onPairCompleted(BluetoothDevice, boolean)
,
ConnectionCallbacks.onPasskeyGenerated(BluetoothDevice, int)
public boolean passkeyReply(boolean accept, int passkey)
This operation may only be performed after received a passkey request.
accept
- true if the passkey request should be accepted, false otherwise.passkey
- the passkey value (6-digits PIN code).ConnectionCallbacks.onPairCompleted(BluetoothDevice, boolean)
public boolean discoverServices()
This operation may only be performed while connected to this device.
ConnectionCallbacks.onServicesDiscovered(BluetoothDevice)