This plugin enables you to harness the power of the Intel® Context Sensing SDK in your Android* Cordova* application. Intel® Context Sensing SDK is a library available for Android* that helps you easily incorporate context-aware capabilities and services into your applications. The SDK is flexible, offering several methods to use the services, either independently or together. The SDK includes Context APIs, which are useful to create context-aware applications by taking advantage of many built-in context providers.
Learn More
To learn more about the Intel® Context Sensing SDK, head over to https://software.intel.com/en-us/context-sensing-sdk and see the full documentation and information about the providers.
The plugin is available for Cordova apps via NPM* or Github*.
cordova plugin add context-sensing-plugin-for-cordova cordova plugin add https://github.com/mobiletools/context-sensing-cordova/.git
Context Providers
There are currently thirteen providers available for you to subscribe to. Each provider will send data back asynchronously to your application. You can also request the value of a provider at any given time. Below is a list of the context providers available.
- LOCATION
- TERMINAL_CONTEXT
- ACTIVITY_RECOGNITION
- INSTANT_ACTIVITY
- AUDIO
- PEDOMETER
- BATTERY
- NETWORK
- DEVICE_POSITION
- TAPPING
- SHAKING
- GESTURE_FLICK
- GESTURE_EAR_TOUCH
Using the providers
You can find a full example application at https://github.com/mobiletools/context-sensing-cordova/tree/master/example . First your application must first enable the sensing daemon. We recommend doing this after the Cordova device ready event.
document.addEventListener("deviceready",function(){ intel.context.start(function() { //sensing daemon started }, function(res) { alert("Error starting daemon " + res); }) });
Once the daemon has started, you can register to listen to context sensing events. Below we will show how to listen for TERMINAL_CONTEXT. This provider is similar to device orientation, but with additional data that includes if the device is facing up or down, on the desk, etc.
intel.context.enableSensing('TERMINAL_CONTEXT',function(data){ console.log("The orientation is "+data.orientation); console.log("The face direction is "+data.face); },function(err){ console.log("Error "+err); });
Any time the terminal context gets changed our callback function will get executed. If you want to request the value at a given time, use the getItem function.
intel.context.getItem('TERMINAL_CONTEXT',function(data){ console.log("The orientation is "+data.orientation); console.log("The face direction is "+data.face); },function(err){ console.log("Error "+err); });
Return Values
Each provider returns a JSON object with data. The following shows examples for each provider.
TERMINAL_CONTEXT
{orientation: "ORIENTATION_UNKNOWN", face: "FACE_UP"}
ACTIVITY_RECOGNITION
{"activities":[{"probability":0,"name":"NONE"},{"probability":0,"name":"WALKING"},{"probability":0,"name":"BIKING"},{"probability":0,"name":"RUNNING"},{"probability":0,"name":"INCAR"},{"probability":0,"name":"INTRAIN"},{"probability":0,"name":"RANDOM"},{"probability":100,"name":"SEDENTARY"}]}
INSTANT_ACTIVITY
{mType: "SEDENTARY"}
AUDIO
{"audio":[{"probability":0,"name":"SPEECH"},{"probability":21,"name":"CROWD_CHATTER"},{"probability":11,"name":"MUSIC"},{"probability":45,"name":"MECHANICAL"},{"probability":20,"name":"MOTION"}],"mTimestamp":1439389273250}
PEDOMETER
{"partOfDay":{"night":0,"noon":0,"morning":6,"midnight":0,"evening":0,"afternoon":0},"currentSteps":6}
BATTERY
{"timeOnBattery":0,"remainingBatteryLife":0,"plugged":true,"level":94,"status":"CHARGING","batteryPresent":true,"temperature":27}
NETWORK
{"nearNetworks":[{"ssid":"","signalStrength":"VERY_LOW","securityType":"WPA2"},{"ssid":"IDPDK-6dd8","signalStrength":"VERY_LOW","securityType":"WPA2"},{"ssid":"HP-Print-B5-Officejet Pro X476dw","signalStrength":"LOW","securityType":"WPA2"},{"ssid":"CBCI-1DA1-2.4","signalStrength":"VERY_LOW","securityType":"WPA2"},{"ssid":"Guest","signalStrength":"EXCELLENT","securityType":"OPEN"},{"ssid":"Lancaster2","signalStrength":"VERY_LOW","securityType":"WPA"},{"ssid":"xfinitywifi","signalStrength":"VERY_LOW","securityType":"OPEN"},{"ssid":"NETWORK1","signalStrength":"VERY_LOW","securityType":"WPA2"}],"cellLocation":"2978,140635817,-1","signalStrength":"EXCELLENT","trafficSent":0.45,"networkType":"WIFI","roamingActive":false,"onlineTime":0,"phoneType":"GSM","securityType":"WPA2","linkSpeed":72,"trafficReceived":35.91,"ssid":"NETWORK1","ip":"fe80::ce3a:61ff:feea:d871%wlan0"}
DEVICE_POSITION
{"mType":"ON_DESK"} Object {mType: "BAG_MOTION"}
TAPPING
{"mType":"SINGLE_TAP"}
GESTURE_FLICK
{"mType":"FLICK_UP"}
GESTURE_EAR_TOUCH
{"mType":"EAR_TOUCH_BACK"}