Activity Recognition
PUBLISHED
The activity recognizer can monitor user activities. You can detect walking and running activity. You can also recognize the stationary state and activities on a moving vehicle.
Prerequisites
To use the functions and data types of the Activity Recognition API (in mobile [1] and wearable [2] applications), include the <activity_recognition.h>
header file in your application:
#include <activity_recognition.h>
Detecting Activities
To set and unset callback functions for the activity monitor and retrieve details from the received activity data:
- Create a handle for activity monitoring using the
activity_create()
function:activity_h handle; activity_create(&handle);
- To subscribe to notifications about specific activity state changes, invoke the
activity_start_recognition()
function to register a callback function.When specific activity data is received, the registered callback is invoked.
The following example starts the activity monitor to receive notifications when the
ACTIVITY_WALK
activity is detected. Any of theactivity_type_e
enumerators (in mobile [3] and wearable [4] applications) can be used in place of theACTIVITY_WALK
value.activity_start_recognition(handle, ACTIVITY_WALK, example_activity_callback, NULL);
- When the registered callback is invoked, the current activity is delivered as a parameter, and you can extract the accuracy of the recognized activity:
void example_activity_callback(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void *user_data) { int result; activity_accuracy_e accuracy; result = activity_get_accuracy(data, &accuracy); if (result != ACTIVITY_ERROR_NONE) /* Error handling */ }
- When activity monitoring is no longer needed, unset the callback function and destroy the handle:
activity_stop_recognition(handle); activity_release(handle);