Human Activity Monitor: Retrieving User Activity Data from the Various Device Sensors
This tutorial demonstrates how you can monitor user activity.
The Human Activity Monitor API is optional for both Tizen mobile and wearable profiles, which means that it may not be supported in all mobile and wearable devices. The Human Activity Monitor API is partly supported on the Tizen Emulators (only heart-rate monitoring).
Warm-up
Become familiar with the Human Activity Monitor API basics by learning about:
-
Retrieving Data
Start the data collection and get monitor data.
-
Receiving Notifications on Pedometer Data Changes
Track the changes in the step count.
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 the HumanActivityMonitorManager interface (in mobile and wearable 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 smartwatch"); } tizen.humanactivitymonitor.start("WRIST_UP", onchangedCB)
- When the a heart-rate monitor (HRM) is enabled, you can get the current data using the getHumanActivityData() method of the HumanActivityMonitorManager 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 the HumanActivityMonitorManager 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:
- To register an event handler for accumulative pedometer changes, use the setAccumulativePedometerListener() method of the HumanActivityMonitorManager interface (in mobile and wearable applications):
function onchangedCB(pedometerInfo) { console.log("Step status : " + pedometerInfo.stepStatus); console.log("Speed : " + pedometerInfo.speed); console.log("Walking frequency : " + pedometerInfo.walkingFrequency); /* Unregisters 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 the HumanActivityMonitorManager interface:
tizen.humanactivitymonitor.unsetAccumulativePedometerListener()