Managing connection

How to manage InputStick connection?

Use methods from InputStickHID class (com.inputstick.api.basic.InputStickHID):

 

public static void connect(Application app);

Use this method to initiate connection with InputStick. InputStickUtility application must be installed on the device. It will take care of enabling Bluetooth radio, selecting InputStick device (if more that one is available), authentication and encryption (if InputStick is password protected). When this method is used, your application does not need to have Bluetooth permissions.

In most cases this is the easiest, fastest and most user friendly way of connecting with InputStick.

 

 

public static void connect(Application app, String mac, byte[] key);

Use this method if you do not want to use InputStickUtility application. Note that in this case, you must provide Bluetooth MAC address and encryption key (if InputStick is password protected, otherwise use null). Your application will need Bluetooth permissions: android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN.

 

InputStickHID.disconnect();

Closes connection to InputStick.

 

Managing connection state:

public static int getState();

Returns current connection state, which is represented by one of following values:

 

ConnectionManager.STATE_DISCONNECTED - initial state, idle,

ConnectionManager.STATE_FAILURE - failure occurred, Note: state will change to STATE_DISCONNECTED,

ConnectionManager.STATE_CONNECTING - device is currently trying to establish Bluetooth connection,

ConnectionManager.STATE_CONNECTED - Bluetooth connection is now established, InputStick can receive data, however USB host may not be ready to accept USB HID reports yet,

ConnectionManager.STATE_READY - USB host is now ready to receive USB HID reports.

 

public static void addStateListener(InputStickStateListener listener);

Adds new InputStickStateListener, which will be notified about changes of connection state.

 

public static void removeStateListener(InputStickStateListener listener);

Removes listener.

 

Handling errors.

When error occurs, connection state will change from STATE_CONNECTING, STATE_CONNECTED, STATE_READY to STATE_FAILURE and then to STATE_DISCONNECTED. When state if set to STATE_FAILURE you can retrieve information about the error:

 

public static int getErrorCode();

Returns error code.

 

To get more details, use com.inputstick.api.InputStickError class:

 

public static String getErrorType(int errorCode);

Returns error type (category): "Bluetooth", "Hardware" etc.

 

public static String getErrorMessage(int errorCode);

Returns error message: "Failed to connect", "Connection lost" etc.

 

public static String getFullErrorMessage(int errorCode);

Returns full error message (error type and error message), example: "Bluetooth - Failed to connect".

Zobacz także:

gallery

Blog

gallery

YouTube

GooglePlay

AppStore

Ta strona korzysta z plików cookies. Dowiedz się więcej. Regulamin sklepu. Copyright © 2017 InputStick. All Rights Reserved. Joomla! is Free Software released under the GNU GPL. Template by RocketTheme. Wszystkie nazwy oraz znaki towarowe są własnością ich prawowitych właścicieli i są umieszczone jedynie w celach informacyjnych.