-
Notifications
You must be signed in to change notification settings - Fork 6
Communicating with Neyya
We are using broadcast receiver to communicate with the SDK service and your application.
###List of actions for the intent filters for broadcast receivers.
- BROADCAST_COMMAND_SEARCH
- BROADCAST_COMMAND_STOP_SEARCH
- BROADCAST_COMMAND_CONNECT
- BROADCAST_COMMAND_DISCONNECT
- BROADCAST_COMMAND_SETTINGS
- BROADCAST_COMMAND_GET_STATE
- BROADCAST_STATE
- BROADCAST_DEVICES
- BROADCAST_GESTURE
- BROADCAST_ERROR
- BROADCAST_INFO
Use the second set of actions to send command to the SDK.
Use the first set of actions to register a broadcast receiver in your application. Then your incoming channel will also be ready.
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(MyService.BROADCAST_STATE);
intentFilter.addAction(MyService.BROADCAST_DEVICES);
intentFilter.addAction(MyService.BROADCAST_GESTURE);
intentFilter.addAction(MyService.BROADCAST_ERROR);
intentFilter.addAction(MyService.BROADCAST_INFO);
registerReceiver(mNeyyaUpdateReceiver, intentFilter);
Access the integer data coming through the this broadcast using this code.
int status = intent.getIntExtra(MyService.DATA_STATE, 0);
The integer status points the state of service. The states are
- STATE_DISCONNECTED
- STATE_AUTO_DISCONNECTED
- STATE_SEARCHING
- STATE_SEARCH_FINISHED
- STATE_CONNECTING
- STATE_CONNECTED
- STATE_CONNECTED_AND_READY
Example :
private final BroadcastReceiver mNeyyaUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (MyService.BROADCAST_STATE.equals(action)) {
int status = intent.getIntExtra(MyService.DATA_STATE, 0);
if (status == MyService.STATE_DISCONNECTED) {
showStatus("Disconnected");
} else if (status == MyService.STATE_SEARCHING) {
showStatus("Searching");
} else if (status == MyService.STATE_SEARCH_FINISHED) {
showStatus("Searching finished");
} else {
showStatus(status + "");
}
}
}
}
There are two types if errors. One is Neyya Errors and second one is Bluetooth connection level errors.
- ERROR_NO_BLE
- ERROR_BLUETOOTH_NOT_SUPPORTED
- ERROR_BLUETOOTH_OFF
- ERROR_NOT_NEYYA
- ERROR_BONDING_FAILED
- ERROR_SERVICE_DISCOVERY_FAILED
- ERROR_SERVICE_NOT_FOUND
- ERROR_CHARACTERISTICS_NOT_FOUND
- ERROR_DEVICE_DISCONNECTED
- ERROR_PACKET_DELIVERY_FAILED
- ERROR_NAME_LENGTH_EXCEEDS
- ERROR_REMOTE_COMMAND_EXECUTION_FAILED
- ERROR_UNKNOWN_HAND_REQUEST
- ERROR_UNKNOWN_GESTURE_SPEED_REQUEST
These are system level errors. This errors will also be broadcasted to the app is it occurs.
Both type of errors can be parsed using the below function to get the error message.
String errorMessage = NeyyaError.parseError(errorNumber);
Example :
private final BroadcastReceiver mNeyyaUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (MyService.BROADCAST_ERROR.equals(action)) {
int errorNo = intent.getIntExtra(MyService.DATA_ERROR_NUMBER, 0);
String errorMessage = intent.getStringExtra(MyService.DATA_ERROR_MESSAGE);
logd("Error occurred. Error number - " + errorNo + " Message - " + errorMessage);
}
}
};
Next : Search and connect Neyya