Cortex for Android


  1. Setup you application with the Sense Android library as described here
  2. Get the with native libraries and JAVA wrappers
  3. Create a folder with the name libs in the root of your project and extract into it. This will add a folder with the name armeabi with the native libraries and a library with the java wrappers namedcortex.jar.
  4. Add cortex.jar to your project’s build path, right click on the file then select “Build Path” -> “Add to Build Path”

Android Example Code

Context information can be can be pushed into your application by simply enabling and registering one of the DataProcessors/Producers from the cortex library.

Below is an code example of how to get Physical Activity information in your application.

package nl.sense.demo.cortex.activity;

    import android.util.Log;
    import nl.sense_os.cortex.dataprocessor.PhysicalActivity;
    import nl.sense_os.platform.SensePlatform;
    import nl.sense_os.service.shared.DataProcessor;
    import nl.sense_os.service.shared.SensorDataPoint;

    public class PhysicalActivityDemo {

        // The name of the DataProcessor 
        private static String TAG = "My Physical Activity Demo";

        public PhysicalActivityDemo(SensePlatform sensePlatform)
            // Create the actual PhysicalActivity DataProcessor, which will be registered at the Sense Service with the given name (TAG)
            PhysicalActivity physicalActivity = new PhysicalActivity(TAG, sensePlatform.getService().getSenseService());

            // Subscribe a DataProcessor to get data from the PhysicalActivity DataProducer/Processor
            physicalActivity.addSubscriber(new DataProcessor(){

                // receive data from the subscribed DataProducer
                public void onNewData(SensorDataPoint dataPoint) 
                    // Print the classified physical activity output 
                    Log.d(TAG, dataPoint.getJSONValue().toString());            

                // nothing to do here
                public void startNewSample() {}

                // get data at the rate of the platform's interval 
                public boolean isSampleComplete() { return true;}

After your application successfully created a bind with the Sense Plaform you can enable the appropriate sensors and start receiving context information (example).

service.setPrefBool(Motion.BURSTMODE, true);  
    service.setPrefBool(Motion.GYROSCOPE, true);  
    service.setPrefBool(Motion.LINEAR_ACCELERATION, true);  
    PhysicalActivityDemo physicalActivityDemo = new PhysicalActivityDemo(sensePlatform);