public class BluetoothReaderService
extends java.util.Observable
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEVICE_NAME_KEY |
static int |
MESSAGE_STATE_CHANGE |
static java.lang.String |
REASON_KEY |
static int |
STATE_CONNECT_FAILED |
static int |
STATE_CONNECTED |
static int |
STATE_CONNECTING |
static int |
STATE_DISCONNECTED |
static int |
STATE_NONE |
Constructor and Description |
---|
BluetoothReaderService(android.os.Handler handler)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
connect(android.bluetooth.BluetoothDevice device,
boolean secure)
Start the ConnectThread to initiate a connection to a remote device.
|
void |
connected(android.bluetooth.BluetoothSocket socket,
android.bluetooth.BluetoothDevice device,
java.lang.String socketType)
Start the ConnectedThread to begin managing a Bluetooth connection
|
int |
getState()
Return the current connection state.
|
void |
stop()
Stop all threads
|
void |
write(byte[] out)
Write to the ConnectedThread in an unsynchronized manner
|
public static final int MESSAGE_STATE_CHANGE
public static final java.lang.String DEVICE_NAME_KEY
public static final java.lang.String REASON_KEY
public static final int STATE_NONE
public static final int STATE_DISCONNECTED
public static final int STATE_CONNECTING
public static final int STATE_CONNECTED
public static final int STATE_CONNECT_FAILED
public BluetoothReaderService(android.os.Handler handler)
handler
- A Handler to send messages back to the UI Activitypublic int getState()
public boolean connect(android.bluetooth.BluetoothDevice device, boolean secure)
device
- The BluetoothDevice to connectsecure
- Socket Security type - Secure (true) , Insecure (false)public void connected(android.bluetooth.BluetoothSocket socket, android.bluetooth.BluetoothDevice device, java.lang.String socketType)
socket
- The BluetoothSocket on which the connection was madedevice
- The BluetoothDevice that has been connectedpublic void stop()
public void write(byte[] out)
out
- The bytes to writeConnectedThread#write(byte[])