API reference - nift4/BTLib GitHub Wiki
Welcome to the API reference. This page only documents API methods/classes, not internal methods/classes.
BluetoothService
public static class
This class does all the work to setup and manage Bluetooth connections.
Constructor 1
public BluetoothService(android.app.Activity context, java.util.UUID secureUuid, java.util.UUID insecureUuid)
context is needed. Give simply two hard-coded random UUIDs to the constructor. Difference to Constructor 2: Doesn't enables Bluetooth.
Constructor 2
public BluetoothService(android.app.Activity context, java.util.UUID secureUuid, java.util.UUID insecureUuid, final Callback enablerCallback, final Callback failedCallback)
context is needed. Give simply two hard-coded random UUIDs to the constructor. enablerCallback is called when Bluetooth is enabled. failedCallback is called when Bluetooth usn't enabled and the user cancelled the Bluetooth enable request. Difference to Constructor 1: Enables Bluetooth if needed.
NONE_REASON_CONN_LOST
public static int
Used with getNoneReason() to indicate that the connection was lost.
NONE_REASON_NOT_STARTED
public static int
Used with getNoneReason() to indicate that the Bluetooth Service never started.
NONE_REASON_STOP
public static int
Used with getNoneReason() to indicate that the Bluetooth Service was stopped
NONE_REASON_CONN_FAIL
public static int
Used with getNoneReason() to indicate that the Connection is failed.
Callback
public static interface
Used for some callback methods.
callback
public void callback();
enableBluetooth
public void enableBluetooth(Callback x);
Enable Bluetooth. IMPORTANT: Needs a properly configured getDeviceSelectorResult()
showDeviceSelector
public void showDeviceSelector()
Shows the Device Selector IMPORTANT: Needs a properly configured getDeviceSelectorResult()
getDeviceSelectorResult
public android.bluetooth.BluetoothDevice getDeviceSelectorResult(int requestCode, int resultCode, android.content.Intent data)
Returns the selected BluetoothDevice from the dialog or returns null
if the result wasn't from device selector.
BtData
public static class
Has byte[]
buffer and int
bytes.
bytes is valid bytes from buffer
.
NoBluetoothAdapterFoundException
public static class extends Exception
Thrown by the constructor if no bluetooth adapter was found.
BluetoothDisabledException
public static class extends Exception
Throws when Bluetooth is disabled and can't be enabled.
STATE_NONE
public static int
Used with getState() to indendicate that we're doing nothing. To get the reason, call getNoneReason().
STATE_LISTEN
public static int
Used with getState() to indendicate that we're listening for connection requests.
STATE_CONNECTING
public static int
Used with getState() to indendicate that we're trying to connect.
STATE_CONNECTED
public static int
Used with getState() to indendicate that we're connected.
newMessageAvaiable
public boolean newMessageAvailable()
Returns true if a new message recived.
read
public BtData read()
Returns a recived message or null if nothing recived. Doesnt blocks.
getNoneReason
public int getNoneReason()
Returns the none reason(One of NONE_REASON_NOT_STARTED NONE_REASON_CONN_FAIL NONE_REASON_CONN_LOST or NONE_REASON_STOP). NOTE: Only call if State is None
getState
public int getState()
Returns the State(One of STATE_NONE STATE_LISTEN STATE_CONNECTING or STATE_CONNECTED).
startServer
public void startServer()
Listen for connections. Sets the state. It's recommened to call makeDiscoverable() before.
connect
public void connect(android.bluetooth.BluetoothDevice device, boolean secure)
Connect to another BluetoothDevice. A server must running there if using BTLib.
If you're pairing devices, insecure mode should not show a pair dialog. This makes your App vulberable for Man-in-the-Middle . You should use secure, but I won't force it.
makeDiscoverable
public void makeDiscoverable()
Make this device visible for other devices.
stop
public void stop()
Stop anything BluetoothService-related.
write
public void write(byte[] out)
Send data out to the other device.
AboutActivity
public static class extends android.app.Activity
Run this to show a small about BTLib window. Shows needed License Information.