Gesture Recognition
PUBLISHED
You can set your application to recognize specific user gestures and react when the user performs them. The various recognizable gestures include, for example, when the user taps, shakes up, or picks up the device, or moves it along an axis.
This feature is supported in mobile and wearable applications only.
The main gesture recognition features of the Human Activity Monitor API include:
- Checking the gesture support
You can check whether a specific gesture type is supported on a device.
- Receiving notifications
You can monitor when a defined gesture type is recognized, and receive a notification about the gesture.
Checking the Gesture Support
Some gestures are not supported on all devices because the devices lack the necessary sensors.
To check whether a specific gesture type is supported on the current device, use the isGestureSupported()
method of the HumanActivityMonitorManager
interface (in mobile [1] and wearable [2] applications):
try { var isSupported = tizen.humanactivitymonitor.isGestureSupported('GESTURE_PICK_UP'); console.log('GESTURE_PICK_UP is ' + (isSupported ? 'supported' : 'not supported')); } catch (error) { console.log('Error ' + error.name + ': ' + error.message); }
Receiving Notifications on Recognized Gestures
Learning how to register a listener for gesture recognition allows you to receive notifications about different gestures the user performs with a device:
- To register a listener, use the
addGestureRecognitionListener()
method of theHumanActivityMonitorManager
interface (in mobile [1] and wearable [2] applications):var listenerId; function listener(data) { console.log('Received ' + data.event + ' event on ' + new Date(data.timestamp * 1000) + ' for '+ data.type + ' type'); } function errorCallback(error) { console.log(error.name + ': ' + error.message); } try { listenerId = tizen.humanactivitymonitor.addGestureRecognitionListener('GESTURE_SHAKE', listener, errorCallback); } catch (error) { console.log('Error ' + error.name + ': ' + error.message); }
- To stop receiving the notifications, remove the listener using the
removeGestureRecognitionListener()
method of theHumanActivityMonitorManager
interface with the listener ID:
try { tizen.humanactivitymonitor.removeGestureRecognitionListener(listenerId); } catch (err) { console.log('Exception: ' + err.name); }