Cortex Library for Mobile
  • Getting Started
  • Objective-C API for iOS
    • CortexLib class
    • CortexClient class
    • CortexClientDelegate protocol
  • Java API for Android
    • EmotivLibraryLoader class
    • CortexLib class
    • CortexClient class
  • Additional JSON methods
    • loginWithAuthenticationCode
    • logout
    • queryVirtualHeadsets
    • createVirtualHeadset
    • deleteVirtualHeadset
    • updateVirtualHeadset
    • triggerVirtualHeadsetEvent
    • Virtual headset object
    • freeUpRecords
  • Release Notes
Powered by GitBook
On this page
  • registerResponseHandler
  • authenticate
  • getAuthenticationCode
  • sendRequest
  • close
  1. Java API for Android

CortexClient class

PreviousCortexLib classNextAdditional JSON methods

Last updated 4 years ago

import com.emotiv.CortexClient;

Use CortexClient to send and receive JSON messages to the Cortex library. You must 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 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 . The second argument is the client id of your Cortex application. You can find it on the . The argument requestCode can take any value.

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)

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.

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 .

This function returns an authentication code that you can use to call the JSON API method . You must call this function after you called the function authenticate and get the result of the activity.

initialize
OAuth 2
android.app.Activity
EMOTIV web site
loginWithAuthenticationCode
loginWithAuthenticationCode