CortexClient class
import com.emotiv.CortexClient;
Use CortexClient to send and receive JSON messages to the Cortex library. You must initialize the Cortex library before creating an instance of CortexClient.
registerResponseHandler
public void registerResponseHandler(ResponseHandler responseHandler)
Set a handler to receive the JSON messages from the Cortex library.
The handler is defined like this:
public interface ResponseHandler {
public void processResponse(String responseMessage);
}
The argument responseMessage of the method processResponse is a JSON message sent by the Cortex library.
authenticate
public void authenticate(@NonNull Activity activity,
String clientId,
int requestCode)
This function is to help you log in into Cortex, using OAuth 2 for authentication.
When you call this function, your application displays a web form from the EMOTIV web site. This form requires the user to enter their EmotivID and password.
The first argument is the activity that will display the web form. It must be an object of the type android.app.Activity. The second argument is the client id of your Cortex application. You can find it on the EMOTIV web site. The argument requestCode can take any value.
Your application must get the result from the activity and then call the function getAuthenticationCode. This function returns an authentication code that you can then use to call the JSON API method loginWithAuthenticationCode.
One way to get the result of the activity is to override its function onActivityResult like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
String code = cortexClient.getAuthenticationCode(requestCode, intent);
if (!code.isEmpty()) {
cortexClient.loginWithAuthenticationCode(code);
}
}
getAuthenticationCode
public String getAuthenticationCode(int requestCode, @NonNull Intent intent)
This function returns an authentication code that you can use to call the JSON API method loginWithAuthenticationCode. You must call this function after you called the function authenticate and get the result of the activity.
sendRequest
public void sendRequest(String requestMessage)
Call this method to send a JSON message to the Cortex library. Cortex will respond asynchronously, using the handler you provided in the method registerResponseHandler.
close
public void close()
This method closes the connection to the Cortex library and frees all the resources allocated for this object. Calling this method is optional. After you called it, you must not call any other method on this object.
Last updated