Human Activity Monitor
PUBLISHED
You can access and record human activity data from various sensors and recorders on the device.
This feature is supported in mobile and wearable applications only.
The main features of the Human Activity Monitor API include:
- Retrieving data
You can collect monitor data.
- Managing data recording
You can record human activity data and retrieve the saved data.
- Using user-defined intervals
You can change intervals for collecting data.
- Receiving notifications
You can detect changes in the monitor data.
- Recognizing activity
You can recognize activities, determine whether the user is sleeping, monitor user's sleep or stress level.
Prerequisites
To use the Human Activity Monitor API (in mobile [1] and wearable [2] applications), the application has to request permission by adding the following privileges to the config.xml
file:
<tizen:privilege name="http://tizen.org/privilege/healthinfo"/> <tizen:privilege name="http://tizen.org/privilege/location"/>
Retrieving Data
Enabling the monitor and retrieving data is a basic Human Activity Monitor (HAM) management skill:
- Check whether a sensor is supported using the
tizen.systeminfo.getCapability()
method to get the appropriate capability. - To enable the monitor and start collecting data, use the
start()
method of theHumanActivityMonitorManager
interface (in mobile [3] and wearable [4] applications):
var counter = 0; function onchangedCB(hrmInfo) { console.log('Heart Rate: ' + hrmInfo.heartRate); console.log('Peak-to-peak interval: ' + hrmInfo.rRInterval + ' milliseconds'); counter++; if (counter > 10) { /* Stop the sensor after detecting a few changes */ tizen.humanactivitymonitor.stop('HRM'); } } tizen.humanactivitymonitor.start('HRM', onchangedCB);
You can also detect the wrist up gesture using the
start()
method:function onchangedCB() { console.log('You are looking at your smart watch'); } tizen.humanactivitymonitor.start('WRIST_UP', onchangedCB)
- When the heart rate monitor (HRM) is enabled, you can get the current data using the
getHumanActivityData()
method of theHumanActivityMonitorManager
interface:
function onsuccessCB(hrmInfo) { console.log('Heart rate: ' + hrmInfo.heartRate); } function onerrorCB(error) { console.log('Error occurred: ' + error.message); } tizen.humanactivitymonitor.getHumanActivityData('HRM', onsuccessCB, onerrorCB);
- To disable HAM when it is no longer required, use the
stop()
method of theHumanActivityMonitorManager
interface:
tizen.humanactivitymonitor.stop('HRM');
Managing Data Recording
The Human Activity Monitor API allows you to record and retrieve saved sensor data:
- To check whether a sensor is supported, use the
getCapability()
method of theSystemInfo
interface (in mobile [5] and wearable [6] applications):if (tizen.systeminfo.getCapability('http://tizen.org/feature/sensor.barometer') === false) { console.log('PRESSURE is not supported on this device.'); return; }
- To enable data recording, use the
startRecorder()
method of theHumanActivityMonitorManager
interface (in mobile [3] and wearable [4] applications). Optionally, you can also define an interval and period for the data recording.
var type = 'PRESSURE'; var options = { retentionPeriod: 1 /* 1 hour */ } try { tizen.humanactivitymonitor.startRecorder(type, options); } catch (err) { console.log(err.name + ': ' + err.message); }
To stop recording sensor data, use the
stopRecorder()
method of theHumanActivityMonitorManager
interface:try { tizen.humanactivitymonitor.stopRecorder('PRESSURE'); } catch (err) { console.log(err.name + ': ' + err.message); }
- Before retrieving data, you can specify a time period to be retrieved using the
startTime
andendTime
options in theHumanActivityRecorderQuery
interface (in mobile [7] and wearable [8] applications):
/* To retrieve data from July 1, 2016 to July 31, 2016 */ var query = {}; query['startTime'] = (new Date(2016, 7, 1)).getTime() / 1000; query['endTime'] = (new Date(2016, 7, 31)).getTime() / 1000;
- To get the data sliced by an interval, you can use a combination of the
anchorTime
andinterval
options in theHumanActivityRecorderQuery
interface.Some human activity recorder types do not allow slicing the data by an interval.
/* To retrieve data everyday at midnight */ /* Time is 0:00 internally */ query['anchorTime'] = (new Date(2016, 7, 1, 0, 0)).getTime() / 1000; query['interval'] = 1440; /* Day */
- To read the human activity recorder data from the database, use the
readRecorderData()
method of theHumanActivityMonitorManager
interface with the query.Even if your application never recorded any data, you can access any data that has been recorded in the database by other applications.
function onerror(error) { console.log(error.name + ': ' + error.message); } function onread(data) { for (var idx = 0; idx < data.length; ++idx) { console.log('average pressure: ' + data[idx].average); } } var type = 'PRESSURE'; try { tizen.humanactivitymonitor.readRecorderData(type, query, onread, onerror); } catch (error) { console.log(error.name + ': ' + error.message); }
Using User-defined Intervals
The Human Activity Monitor API allows the user to select their own intervals for collecting samples in a specified range using the HumanActivityMonitorOption
interface (in mobile [9] and wearable [10] applications). Such functionality can be used to build more power-efficient data collection applications (the less often the device gathers data, the less energy is used). You can change the interval according to the device state, for example, when the display is switched off, the sampling interval can be decreased.
- If a human activity type allows setting the interval at which data is sent to the application or setting the sampling interval, the last parameter of the
start()
method can be used to specify this information:var myCallbackInterval = 240000; var mySampleInterval = 10000; function onchangedCB(gpsInfo) { console.log('this callback is called every ' + myCallbackInterval + ' milliseconds'); console.log('the gpsInfo includes the GPS information that is collected every ' + mySampleInterval + ' milliseconds'); } function onerrorCB(error) { console.log('Error occurred. Name:' + error.name + ', message: ' + error.message); } var option = { 'callbackInterval': myCallbackInterval, 'sampleInterval': mySampleInterval }; tizen.humanactivitymonitor.start('GPS', onchangedCB, onerrorCB, option);
- When the heart-rate monitor (HRM) is enabled, you can get the current data using the
getHumanActivityData()
method of theHumanActivityMonitorManager
interface:
function onsuccessCB(hrmInfo) { console.log('Heart rate: ' + hrmInfo.heartRate); } function onerrorCB(error) { console.log('Error occurred: ' + error.message); } tizen.humanactivitymonitor.getHumanActivityData('HRM', onsuccessCB, onerrorCB);
- To disable HAM when it is no longer required, use the
stop()
method of theHumanActivityMonitorManager
interface:
tizen.humanactivitymonitor.stop('HRM');
Receiving Notifications on Pedometer Data Changes
Learning how to register a listener for accumulative allows you to monitor the step count maintained by the system without enabling the Pedometer sensor and the PEDOMETER
monitor is a basic Human Activity Monitor (HAM) management skill:
- To register an event handler for accumulative pedometer changes, use the
setAccumulativePedometerListener()
method of theHumanActivityMonitorManager
interface (in mobile [3] and wearable [4] applications):function onchangedCB(pedometerInfo) { console.log('Step status: ' + pedometerInfo.stepStatus); console.log('Speed: ' + pedometerInfo.speed); console.log('Walking frequency: ' + pedometerInfo.walkingFrequency); /* Deregisters a previously registered listener */ tizen.humanactivitymonitor.unsetAccumulativePedometerListener(); } tizen.humanactivitymonitor.setAccumulativePedometerListener(onchangedCB);
- To stop receiving notifications about the accumulative pedometer changes, use the
unsetAccumulativePedometerListener()
method of theHumanActivityMonitorManager
interface:
tizen.humanactivitymonitor.unsetAccumulativePedometerListener();
Recognizing an Activity
Learning how to register a listener that allows you to recognize and monitor an activity of the given type is a basic Human Activity Monitor (HAM) management skill:
- To register an event handler for recognizing a walking activity, use the
addActivityRecognitionListener()
method of theHumanActivityMonitorManager
interface (in mobile [3] and wearable [4] applications):function errorCallback(error) { console.log(error.name + ': ' + error.message); } function listener(info) { console.log('type: ' + info.type); console.log('timestamp: ' + info.timestamp); console.log('accuracy: ' + info.accuracy); } try { var listenerId = tizen.humanactivitymonitor.addActivityRecognitionListener('WALKING', listener, errorCallback); } catch (error) { console.log(error.name + ': ' + error.message); }
- To stop receiving activity recognition notifications, use the
removeActivityRecognitionListener()
method of theHumanActivityMonitorManager
interface:
var listenerId; function errorCallback(error) { console.log(error.name + ': ' + error.message); } function listener(info) { console.log('type: ' + info.type); console.log('timestamp: ' + info.timestamp); console.log('accuracy: ' + info.accuracy); tizen.humanactivitymonitor.removeActivityRecognitionListener(listenerId, errorCallback); } try { listenerId = tizen.humanactivitymonitor.addActivityRecognitionListener('WALKING', listener, errorCallback); } catch (error) { console.log(error.name + ': ' + error.message); }
Monitoring Sleep
Learning how to monitor user's sleep is a basic Human Activity Monitor (HAM) management skill:
- To enable the monitor and start collecting data, use the
start()
method of theHumanActivityMonitorManager
interface (in mobile [3] and wearable [4] applications):function onchangedCB(sleepInfo) { console.log('Sleep status: ' + sleepInfo.status); console.log('Timestamp: ' + sleepInfo.timestamp + ' milliseconds'); } tizen.humanactivitymonitor.start('SLEEP_MONITOR', onchangedCB);
- To disable the monitor when it is no longer required, use the
stop()
method of theHumanActivityMonitorManager
interface:
tizen.humanactivitymonitor.stop('SLEEP_MONITOR');
Detecting Sleep
Learning how to detect whether the user is asleep is a basic Human Activity Monitor (HAM) management skill:
-
To enable the monitor and start collecting data, use the
start()
method of theHumanActivityMonitorManager
interface (in mobile [3] and wearable [4] applications) withHumanActivityType
set to SLEEP_DETECTOR:function onchangedCB(sleepInfo) { console.log('Sleep status: ' + sleepInfo.status); } tizen.humanactivitymonitor.start('SLEEP_DETECTOR', onchangedCB);
-
To disable the monitor when it is no longer required, use the
stop()
method of theHumanActivityMonitorManager
interface withHumanActivityType
set to SLEEP_DETECTOR:tizen.humanactivitymonitor.stop('SLEEP_DETECTOR');
Monitoring Stress
Learning how to register a listener that allows you to monitor user's stress is a basic Human Activity Monitor (HAM) management skill:
-
To register an event handler for monitoring user stress, use the
addStressMonitorChangeListener()
method of theHumanActivityMonitorManager
interface (in mobile [3] and wearable [4] applications):var listenerId; function errorCallback(error) { console.log(error.name + ": " + error.message); } function listener(label) { console.log("Stress level: " + label); } var ranges = [new tizen.StressMonitorDataRange("Normal",10, 15), new tizen.StressMonitorDataRange("Stress Alarm",15, 17)]; try { listenerId = tizen.humanactivitymonitor.addStressMonitorChangeListener(ranges, listener, errorCallback); } catch (error) { console.log(error.name + ": " + error.message); }
-
To enable receiving data it is need to call sensor's
start()
method withHumanActivityType
set to STRESS_MONITOR:function onchangedCB(info) { console.log("score: " + info.stressScore); } function onerrorCB(error) { console.log("Error occurred, name: " + error.name + ", message: " + error.message); } try { tizen.humanactivitymonitor.start("STRESS_MONITOR", onchangedCB, onerrorCB, {callbackInterval: 1500, sampleInterval: 100}); } catch (err) { console.log(err.name + ": " + err.message); }
-
To disable the monitor when it is no longer required, use the
stop()
andremoveStressMonitorChangeListener()
methods of theHumanActivityMonitorManager
interface:tizen.humanactivitymonitor.stop('STRESS_MONITOR'); tizen.humanactivitymonitor.removeStressMonitorChangeListener(listenerId);
Supported Monitors
The following table introduces the available monitor types and lists the monitor capabilities you can use to determine whether a specific monitor is supported on a device.
Table: Human activity monitors and capabilities
Monitor | Capability | Notes |
---|---|---|
Pedometer and accumulative pedometer | http://tizen.org/feature/sensor.pedometer |
When the pedometer sensor is started, a change callback is invoked when data changes. Use the getHumanActivityData() method to get the current data.
The accumulative pedometer sensor does not have to be started by your application as long as step counting is enabled by any other application or the system. Listener registered with the |
Wrist up | http://tizen.org/feature/sensor.wrist_up |
The wrist up sensor is notified when the relevant gesture is performed. The sensor must be enabled using the start() method. An event listener invoked when the gesture is detected. This sensor does not provide any data. |
Heart rate monitor | http://tizen.org/feature/sensor.heart_rate_monitor |
When the heart rate monitor (HRM) sensor is started, a change callback is invoked when data changes. Use the getHumanActivityData() method to get the current data. |
GPS | http://tizen.org/feature/location.batch |
When the GPS sensor is started, a change callback is invoked when data changes. Use the getHumanActivityData() method to get the current data.
The GPS sensor provides both the current value and a short history of last recorded GPS positions. The sensor supports sampling intervals, which can be used to create more power-efficient applications. |
Sleep monitor | http://tizen.org/feature/sensor.sleep_monitor |
When the sleep sensor is started, a change callback is invoked when data changes. Use the getHumanActivityData() method to get the current data. |
Sleep detector | http://tizen.org/feature/sensor.sleep_monitor |
When the sleep sensor is started, a change callback is invoked when data changes. Use the getHumanActivityData() method to get the current data. |
Activity recognition | http://tizen.org/feature/sensor.activity_recognition |
To recognize an activity, start listening for it using the addActivityRecognitionListener() method. The following activity types can be recognized:
|
Stress monitor | http://tizen.org/feature/sensor.stress_monitor |
To receive information about stress, start listening for it using the addStressMonitorChangeListener() method. |
Supported Recorders in Wearable Applications
The following table introduces the available recorder types and lists the capabilities you can use to determine whether a specific recorder is supported on a device.
Table: Human activity recorders and capabilities
Recorder | Capability | Notes |
---|---|---|
Pressure | http://tizen.org/feature/sensor.barometer |
Use the startRecorder() and stopRecorder() methods to record the pressure sensor data for the specific period of time. Use the readRecorderData() method to read the recorded pressure sensor data. |