All Products
Search
Document Center

SuperApp:Motion detection

Last Updated:Jun 02, 2026

Describes the WVMotion JavaScript APIs for detecting device motion in HTML5 applications and miniapps, including blow gesture detection, gyroscope and shake monitoring, vibration, accelerometer, and compass data.

WVMotion.listenBlow

Starts listening for blow gestures.

Input parameters

  • [number] time: Optional. The interval in seconds at which a blow event fires during a continuous blow. On iOS, the value is in the range [0, 1] and defaults to 0, which lets the system determine the interval. The value increases as the blow continues.

Callback parameters

No callback parameters. The success callback fires if the listener starts successfully; otherwise, the failure callback fires.

Event listening

motion.blow: Fired when a blow gesture is detected while the listener is active.

Event parameters:

  • [number] pass: The blow gesture detection value. This value varies by device. On iOS, it is in the range [0, 1] and increases as the blow continues. On Android, it is always 1.

document.addEventListener('motion.blow', function(e) {
        alert('A blow gesture is detected.');
}, false);

window.WindVane.call('WVMotion', 'listenBlow', {}, function(e) {
        alert('success');
}, function(e) {
        alert('failure:' + JSON.stringify(e));
});

WVMotion.stopListenBlow

Stops listening for blow gestures.

Input parameters

No input parameters.

Callback parameters

No callback parameters. The success callback is always executed.

window.WindVane.call('WVMotion', 'stopListenBlow', {}, function(e) {
        alert('success');
});

WVMotion.listenGyro

Starts or stops listening for gyroscope data.

A device exposes two sensors for detecting orientation: a gyroscope, which reports orientation as Euler angles (roll, pitch, yaw), and a gravity sensor, which measures gravitational force along the device's three axes. Because iOS and Android return gyroscope data in incompatible formats, this API returns gravity sensor data instead to guarantee cross-platform consistency. Your HTML5 page can then derive device orientation from that data using its own algorithm.

Input parameters

  • [boolean] on: Set to true to start listening or false to stop.

  • [number] frequency: The minimum interval in milliseconds between gyroscope events. The actual interval between two consecutive events always exceeds this value.

Callback parameters

No callback parameters. The success callback fires if the listener starts or stops successfully; otherwise, the failure callback fires.

Event listening

motion.gyro: Fired when the device's orientation changes while the listener is active.

Event parameters:

  • [number] x: Gravitational force along the x-axis. Value is in the range [-1, 1].

  • [number] y: Gravitational force along the y-axis. Value is in the range [-1, 1].

  • [number] z: Gravitational force along the z-axis. Value is in the range [-1, 1].

document.addEventListener('motion.gyro', function(e) {
        alert('Device orientation changed.');
}, false);

var params = {
        // Specifies whether to start or stop the gyroscope listener.
        on: true,
        // The time interval for gyroscope events.
        frequency: 100
};
window.WindVane.call('WVMotion', 'listenGyro', params, function(e) {
        alert('success');
}, function(e) {
        alert('failure:' + JSON.stringify(e));
});

WVMotion.listeningShake

Starts or stops listening for shake gestures.

Input parameters

  • [boolean] on: Set to true to start listening or false to stop.

  • [number] frequency: Optional. The minimum interval in milliseconds between shake events. The actual interval between two consecutive events always exceeds this value. Default: 500.

  • [number] shakeThreshold: Optional. The acceleration threshold for a valid shake. Any acceleration exceeding this value is counted as a shake. Default: 1.2.

  • [number] shakeNum: Optional. The number of shakes required to trigger a shake event. Default: 1.

Callback parameters

No callback parameters. The success callback fires if the listener starts or stops successfully; otherwise, the failure callback fires.

Event listening

motion.shake: Fired when the user shakes the device while the listener is active.

Event parameters:

  • [number] x: Acceleration along the x-axis.

  • [number] y: Acceleration along the y-axis.

  • [number] z: Acceleration along the z-axis.

document.addEventListener('motion.shake', function(e) {
        alert('A shake gesture is detected.');
}, false);

var params = {
        // Specifies whether to start or stop listening for shake gestures.
        on: true
};
window.WindVane.call('WVMotion', 'listeningShake', params, function(e) {
        alert('success');
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
})

WVMotion.vibrate

Vibrates the device.

Input parameters

  • [int] duration: Optional. The vibration duration in milliseconds. Defaults to a system-determined duration. Available only on WindVane for Android; may not work on all device models.

Callback parameters

No callback parameters. The success callback is always executed.

window.WindVane.call('WVMotion', 'vibrate', {});

var params = {
        // The duration of the vibration.
        duration: 7000
};
window.WindVane.call('WVMotion', 'vibrate', params);

WVMotion.startAccelerometer

Note

This API is available only in WindVane for Android 1.0.3.4 or later.

Starts listening for accelerometer data.

Input parameters

  • [string] interval: Optional. The callback frequency for accelerometer data. Default: 'normal'. Valid values:

    • ui: Suitable for UI updates. Callbacks fire approximately every 60 ms.

    • game: Suitable for game updates. Callbacks fire approximately every 20 ms.

    • normal: Standard frequency. Callbacks fire approximately every 200 ms.

Callback parameters

Parameters for a success callback:

  • No callback parameters.

Parameters for a failure callback:

  • [string] msg: A message describing the failure.

Event listening

WVMotion.Event.accelerometer: Fired when new accelerometer data is received.

Event parameters:

  • [float] x: Acceleration along the x-axis.

  • [float] y: Acceleration along the y-axis.

  • [float] z: Acceleration along the z-axis.

document.addEventListener('WVMotion.Event.accelerometer', function (e) {
        alert('event accelerometer: ' + JSON.stringify(e.param));
});

var params = {
  interval: 'normal'
};

window.WindVane.call('WVMotion', 'startAccelerometer', params, function(e) {
}, function(e) {
        alert('startAccelerometer failure: ' + JSON.stringify(e));
});

WVMotion.stopAccelerometer

Note

This API is available only in WindVane for Android 1.0.3.4 or later.

Stops listening for accelerometer data.

Input parameters

  • No input parameters.

Callback parameters

No callback parameters. The success callback is always executed.

window.WindVane.call('WVMotion', 'stopAccelerometer', {});

WVMotion.startCompass

Note

This API is available only in WindVane for Android 1.0.3.4 or later.

Starts listening for compass data.

Input parameters

  • [string] interval: Optional. The callback frequency for compass data. Default: 'normal'. Valid values:

    • ui: Suitable for UI updates. Callbacks fire approximately every 60 ms.

    • game: Suitable for game updates. Callbacks fire approximately every 20 ms.

    • normal: Standard frequency. Callbacks fire approximately every 200 ms.

Callback parameters

Parameters for a success callback:

  • No callback parameters.

Parameters for a failure callback:

  • [string] msg: A message describing the failure.

Event listening

WVMotion.Event.compass: Fired when new compass data is received.

Event parameters:

  • [float] direction: The angle in degrees between the direction the device faces and geographic north. Value is in the range [0, 360).

  • [long] timestamp: The timestamp when the data was captured.

document.addEventListener('WVMotion.Event.compass', function (e) {
        alert('event compass: ' + JSON.stringify(e.param));
});

var params = {
  interval: 'normal'
};

window.WindVane.call('WVMotion', 'startCompass', params, function(e) {
}, function(e) {
        alert('startCompass failure: ' + JSON.stringify(e));
});

WVMotion.stopCompass

Note

This API is available only in WindVane for Android 1.0.3.4 or later.

Stops listening for compass data.

Input parameters

  • No input parameters.

Callback parameters

No callback parameters. The success callback is always executed.

window.WindVane.call('WVMotion', 'stopCompass', {});