How to judge if the device is in vehicle

This code shows how to recognize the activity that the Tizen device is in vehicle.
#include <activity_recognition.h>
    ...
    bool supported = false;
    activity_is_supported(ACTIVITY_IN_VEHICLE, &supported);
    if (!supported) {
        // Not supported
    }
    ...
    activity_h handle;
    result = activity_create(&handle);
    if (result != ACTIVITY_ERROR_NONE) {
        // Error
    }
    result = activity_start_recognition(handle, ACTIVITY_IN_VEHICLE, activity_cb, NULL);
    if (result != ACTIVITY_ERROR_NONE) {
        // Error
    }
    ...
    void activity_cb(activity_type_e type, const activity_data_h data, double timestamp, activity_error_e error, void *user_data)
    {
        int result;
        if (error != ACTIVITY_ERROR_NONE) {
           // Error
            return;
        }

        if (type == ACTIVITY_IN_VEHICLE) {
            // ...
        }
    }
    ...
activity_stop_recognition(handle);
activity_release(handle);

Responses

0 Replies