public class DeviceConnectionProvider
extends java.lang.Object
ConfigurableDevice object.
See method getConnection(ConfigurableDevice).
Usage:
DeviceConnectionProvider connectionProvider = new DeviceConnectionProvider(this);
connectionProvider.connectToService(new DeviceConnectionProvider.ConnectionProviderCallback() {
@Override public void onConnectedToService() {
// At this point you can obtain connection from ConnectionProvider
DeviceConnection connection = connectionProvider.getConnection(device);
connection.connect(new DeviceConnectionCallback() {
@Override public void onConnected() {
// At this point Bluetooth connection is established.
log("Connected to device");
}
@Override public void onAuthenticated(DeviceConnection connection) {
// At this point device is connected and authenticated.
readSettings(connection);
readSensors(connection);
}
@Override public void onDisconnected() {
log("Disconnected from device");
}
@Override public void onConnectionFailed(DeviceConnectionException exception) {
handleException(exception);
}
});
....
@Override protected void onDestroy() {
connectionProvider.destroy();
super.onDestroy();
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
DeviceConnectionProvider.ConnectionProviderCallback |
| Constructor and Description |
|---|
DeviceConnectionProvider(android.content.Context context) |
| Modifier and Type | Method and Description |
|---|---|
void |
connectToService(DeviceConnectionProvider.ConnectionProviderCallback callback)
Connects to the connection service.
|
void |
destroy()
Destroys service and kills all current connections.
|
DeviceConnection |
getConnection(ConfigurableDevice device)
Gets or creates new connection for given configurable device.
|
DeviceConnection |
getConnectionForStorageRead(ConfigurableDevice device)
Gets or creates new connection for given configurable device without authorisation.
|
public DeviceConnectionProvider(android.content.Context context)
public void connectToService(DeviceConnectionProvider.ConnectionProviderCallback callback)
DeviceConnectionProviderServicecallback - Callback called when connected to Android service.public DeviceConnection getConnection(ConfigurableDevice device)
Note: For not supported devices it return null.
Note: Service must be connected first, otherwise it will throw an exception.
device - configurable device object. It can be obtained from BeaconManager.public DeviceConnection getConnectionForStorageRead(ConfigurableDevice device)
Note: For not supported devices it return null.
Note: Service must be connected first, otherwise it will throw an exception.
device - configurable device object. It can be obtained from BeaconManager.public void destroy()