public class

DeviceManager

extends Object
java.lang.Object
   ↳ com.openxc.interfaces.bluetooth.DeviceManager

Class Overview

The DeviceManager collects the functions required to connect to and open a socket to the Bluetooth device. The device must be previously bonded, as this class does not initiate discovery.

Summary

Constants
String KNOWN_BLUETOOTH_DEVICE_PREFERENCES
String KNOWN_BLUETOOTH_DEVICE_PREF_KEY
String LAST_CONNECTED_BLUETOOTH_DEVICE_PREF_KEY
Fields
public static final UUID RFCOMM_UUID
Public Constructors
DeviceManager(Context context)
The DeviceManager requires an Android Context in order to send the intent to enable Bluetooth if it isn't already on.
Public Methods
BluetoothSocket connect(String targetAddress)
Connect to the target device and open a socket.
BluetoothSocket connect(BluetoothDevice device)
Set<BluetoothDevice> getCandidateDevices()
BluetoothDevice getLastConnectedDevice()
Set<BluetoothDevice> getPairedDevices()
boolean isConnecting()
BluetoothServerSocket listen()
void startDiscovery()
void stop()
Immediately cancel any pending Bluetooth operations.
void storeLastConnectedDevice(BluetoothDevice device)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String KNOWN_BLUETOOTH_DEVICE_PREFERENCES

Constant Value: "known_bluetooth_devices"

public static final String KNOWN_BLUETOOTH_DEVICE_PREF_KEY

Constant Value: "known_bluetooth_devices"

public static final String LAST_CONNECTED_BLUETOOTH_DEVICE_PREF_KEY

Constant Value: "last_connected_bluetooth_device"

Fields

public static final UUID RFCOMM_UUID

Public Constructors

public DeviceManager (Context context)

The DeviceManager requires an Android Context in order to send the intent to enable Bluetooth if it isn't already on.

Public Methods

public BluetoothSocket connect (String targetAddress)

Connect to the target device and open a socket. This method will block while waiting for the device. Returns a socket connected to the device.

public BluetoothSocket connect (BluetoothDevice device)

public Set<BluetoothDevice> getCandidateDevices ()

public BluetoothDevice getLastConnectedDevice ()

public Set<BluetoothDevice> getPairedDevices ()

public boolean isConnecting ()

public BluetoothServerSocket listen ()

public void startDiscovery ()

public void stop ()

Immediately cancel any pending Bluetooth operations. The BluetoothSocket.connect() function blocks while waiting for a connection, but it's thread safe and we can cancel that by calling close() on it at any time. Importantly we don't want to close the socket any other time, becauase we want to leave that up to the user of the socket - if you call close() twice, or close Input/Ouput streams associated with the socket simultaneously, it can cause a segfault due to a bug in some Android Bluetooth stacks. Awesome!

public void storeLastConnectedDevice (BluetoothDevice device)