Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

729 lines (600 sloc) 31.003 kb
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
<meta name="generator" content="joDoc">
<title>Apache Cordova API Documentation</title>
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="mobile.css" media="only screen and (max-device-width: 1024px)">
<link rel="stylesheet" type="text/css" href="prettify/prettify.css">
</head>
<body>
<div id="header">
<h1><a href="index.html">Apache <strong>Cordova</strong> Documentation</a></h1>
<small>
<select><optgroup label="English" value="en">
<option value="edge">edge</option>
<option value="2.0.0rc1">2.0.0rc1</option>
<option selected value="2.0.0">2.0.0</option>
<option value="1.9.0rc1">1.9.0rc1</option>
<option value="1.9.0">1.9.0</option>
<option value="1.8.1">1.8.1</option>
<option value="1.8.0rc1">1.8.0rc1</option>
<option value="1.8.0">1.8.0</option>
<option value="1.7.0rc1">1.7.0rc1</option>
<option value="1.7.0">1.7.0</option>
<option value="1.6.1">1.6.1</option>
<option value="1.6.0rc1">1.6.0rc1</option>
<option value="1.6.0">1.6.0</option>
<option value="1.5.0rc1">1.5.0rc1</option>
<option value="1.5.0">1.5.0</option>
<option value="1.4.1">1.4.1</option>
<option value="1.4.0rc1">1.4.0rc1</option>
<option value="1.4.0">1.4.0</option>
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
<option value="1.0.0rc3">1.0.0rc3</option>
<option value="1.0.0rc2">1.0.0rc2</option>
<option value="1.0.0rc1">1.0.0rc1</option>
<option value="1.0.0">1.0.0</option>
<option value="0.9.6">0.9.6</option>
<option value="0.9.5.1">0.9.5.1</option>
<option value="0.9.5">0.9.5</option>
<option value="0.9.4">0.9.4</option>
<option value="0.9.3">0.9.3</option>
<option value="0.9.2">0.9.2</option>
</optgroup>
<optgroup label="Español" value="es"><option value="1.0.0">1.0.0</option></optgroup>
<optgroup label="Français" value="fr">
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
</optgroup>
<optgroup label="Japanese" value="jp">
<option value="1.8.1">1.8.1</option>
<option value="1.7.0">1.7.0</option>
<option value="0.9.5">0.9.5</option>
</optgroup></select></small>
</div>
<div id="subheader">
<h1>Accelerometer</h1>
<small><select><option value="Accelerometer">Accelerometer</option>
<option value="Accelerometer_methods">      - Methods</option>
<option value="Accelerometer_arguments">      - Arguments</option>
<option value="Accelerometer_objects_read_only">      - Objects (Read-Only)</option>
<option value="Accelerometer_permissions">      - Permissions</option>
<option value="accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</option>
<option value="accelerometer.getCurrentAcceleration_description">      - Description</option>
<option value="accelerometer.getCurrentAcceleration_supported_platforms">      - Supported Platforms</option>
<option value="accelerometer.getCurrentAcceleration_quick_example">      - Quick Example</option>
<option value="accelerometer.getCurrentAcceleration_full_example">      - Full Example</option>
<option value="accelerometer.getCurrentAcceleration_iphone_quirks">      - iPhone Quirks</option>
<option value="accelerometer.watchAcceleration">accelerometer.watchAcceleration</option>
<option value="accelerometer.watchAcceleration_description">      - Description</option>
<option value="accelerometer.watchAcceleration_supported_platforms">      - Supported Platforms</option>
<option value="accelerometer.watchAcceleration_quick_example">      - Quick Example</option>
<option value="accelerometer.watchAcceleration_full_example">      - Full Example</option>
<option value="accelerometer.watchAcceleration_iphone_quirks">      - iPhone Quirks</option>
<option value="accelerometer.clearWatch">accelerometer.clearWatch</option>
<option value="accelerometer.clearWatch_supported_platforms">      - Supported Platforms</option>
<option value="accelerometer.clearWatch_quick_example">      - Quick Example</option>
<option value="accelerometer.clearWatch_full_example">      - Full Example</option>
<option value="Acceleration">Acceleration</option>
<option value="Acceleration_properties">      - Properties</option>
<option value="Acceleration_description">      - Description</option>
<option value="Acceleration_supported_platforms">      - Supported Platforms</option>
<option value="Acceleration_quick_example">      - Quick Example</option>
<option value="Acceleration_full_example">      - Full Example</option>
<option value="accelerometerSuccess">accelerometerSuccess</option>
<option value="accelerometerSuccess_parameters">      - Parameters</option>
<option value="accelerometerSuccess_example">      - Example</option>
<option value="accelerometerError">accelerometerError</option>
<option value="accelerometerOptions">accelerometerOptions</option>
<option value="accelerometerOptions_options">      - Options</option></select></small>
</div>
<div id="sidebar">
<div class="vertical_divider"></div>
<h1>API Reference</h1>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a></li>
<li><a href="cordova_camera_camera.md.html#Camera">Camera</a></li>
<li><a href="cordova_media_capture_capture.md.html#Capture">Capture</a></li>
<li><a href="cordova_compass_compass.md.html#Compass">Compass</a></li>
<li><a href="cordova_connection_connection.md.html#Connection">Connection</a></li>
<li><a href="cordova_contacts_contacts.md.html#Contacts">Contacts</a></li>
<li><a href="cordova_device_device.md.html#Device">Device</a></li>
<li><a href="cordova_events_events.md.html#Events">Events</a></li>
<li><a href="cordova_file_file.md.html#File">File</a></li>
<li><a href="cordova_geolocation_geolocation.md.html#Geolocation">Geolocation</a></li>
<li><a href="cordova_media_media.md.html#Media">Media</a></li>
<li><a href="cordova_notification_notification.md.html#Notification">Notification</a></li>
<li><a href="cordova_storage_storage.md.html#Storage">Storage</a></li>
</ul>
<h1>Guides</h1>
<ul>
<li><a href="guide_getting-started_index.md.html#Getting%20Started%20Guides">Getting Started Guides</a></li>
<li><a href="guide_command-line_index.md.html#Command-Line%20Usage">Command-Line Usage</a></li>
<li><a href="guide_upgrading_index.md.html#Upgrading%20Guides">Upgrading Guides</a></li>
<li><a href="guide_plugin-development_index.md.html#Plugin%20Development%20Guide">Plugin Development Guide</a></li>
<li><a href="guide_whitelist_index.md.html#Domain%20Whitelist%20Guide">Domain Whitelist Guide</a></li>
<li><a href="guide_cordova-webview_index.md.html#Embedding%20WebView">Embedding WebView</a></li>
<li><a href="_index.html">Keyword Index</a></li>
</ul>
</div>
<div id="scrollable">
<div id="content">
<h1><a name="Accelerometer">Accelerometer</a></h1>
<blockquote>
<p>Captures device motion in the x, y, and z direction.</p>
</blockquote>
<h2>
<a name="Accelerometer_methods">Methods</a>
</h2>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</a></li>
<li><a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a></li>
<li><a href="cordova_accelerometer_accelerometer.md.html#accelerometer.clearWatch">accelerometer.clearWatch</a></li>
</ul>
<h2>
<a name="Accelerometer_arguments">Arguments</a>
</h2>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#accelerometerSuccess">accelerometerSuccess</a></li>
<li><a href="cordova_accelerometer_accelerometer.md.html#accelerometerError">accelerometerError</a></li>
<li><a href="cordova_accelerometer_accelerometer.md.html#accelerometerOptions">accelerometerOptions</a></li>
</ul>
<h2>
<a name="Accelerometer_objects_read_only">Objects (Read-Only)</a>
</h2>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a></li>
</ul>
<h2>
<a name="Accelerometer_permissions">Permissions</a>
</h2>
<h3>Android</h3>
<h4>app/res/xml/plugins.xml</h4>
<pre class="prettyprint"><code>&lt;plugin name="<a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a>" value="org.apache.cordova.AccelListener" /&gt;
</code></pre>
<h3>Bada</h3>
<pre class="prettyprint"><code>No permissions are required.
</code></pre>
<h3>BlackBerry WebWorks</h3>
<h4>www/plugins.xml</h4>
<pre class="prettyprint"><code>&lt;plugin name="<a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a>" value="org.apache.cordova.accelerometer.<a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a>" /&gt;
</code></pre>
<h4>www/config.xml</h4>
<pre class="prettyprint"><code>&lt;feature id="blackberry.system" required="true" version="1.0.0.0" /&gt;
&lt;feature id="org.apache.cordova" required="true" version="1.0.0" /&gt;
</code></pre>
<h3>iOS</h3>
<h4>App/Supporting Files/Cordova.plist</h4>
<pre class="prettyprint"><code>&lt;key&gt;Plugins&lt;/key&gt;
&lt;dict&gt;
&lt;key&gt;<a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a>&lt;/key&gt;
&lt;string&gt;CDVAccelerometer&lt;/string&gt;
&lt;/dict&gt;
</code></pre>
<h3>webOS</h3>
<pre class="prettyprint"><code>No permissions are required.
</code></pre>
<h3>Windows Phone</h3>
<h4>Properties/WPAppManifest.xml</h4>
<pre class="prettyprint"><code>&lt;Capabilities&gt;
&lt;Capability Name="ID_CAP_SENSORS" /&gt;
&lt;/Capabilities&gt;
</code></pre>
<p>Reference: <a class="external" href="http://msdn.microsoft.com/en-us/library/ff769509%28v=vs.92%29.aspx">Application Manifest for Windows Phone</a></p>
<hr>
<h1><a name="accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</a></h1>
<p>Get the current acceleration along the x, y, and z axis.</p>
<pre class="prettyprint"><code>navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</a>(<a href="cordova_accelerometer_accelerometer.md.html#accelerometerSuccess">accelerometerSuccess</a>, <a href="cordova_accelerometer_accelerometer.md.html#accelerometerError">accelerometerError</a>);
</code></pre>
<h2>
<a name="accelerometer.getCurrentAcceleration_description">Description</a>
</h2>
<p>The accelerometer is a motion sensor that detects the change (delta) in movement relative to the current device orientation. The accelerometer can detect 3D movement along the x, y, and z axis.</p>
<p>The acceleration is returned using the <code><a href="cordova_accelerometer_accelerometer.md.html#accelerometerSuccess">accelerometerSuccess</a></code> callback function.</p>
<h2>
<a name="accelerometer.getCurrentAcceleration_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 5.0 and higher)</li>
<li>iPhone</li>
<li>Windows Phone 7 (Mango)</li>
<li>Bada 1.2 &amp; 2.x</li>
</ul>
<h2>
<a name="accelerometer.getCurrentAcceleration_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>function onSuccess(acceleration) {
alert('<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
};
function onError() {
alert('onError!');
};
navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</a>(onSuccess, onError);
</code></pre>
<h2>
<a name="accelerometer.getCurrentAcceleration_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Example&lt;/title&gt;
&lt;script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" charset="utf-8"&gt;
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</a>(onSuccess, onError);
}
// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration) {
alert('<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
}
// onError: Failed to get the acceleration
//
function onError() {
alert('onError!');
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Example&lt;/h1&gt;
&lt;p&gt;getCurrentAcceleration&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<h2>
<a name="accelerometer.getCurrentAcceleration_iphone_quirks">iPhone Quirks</a>
</h2>
<ul>
<li>iPhone doesn't have the concept of getting the current acceleration at any given point.</li>
<li>You must watch the acceleration and capture the data at given time intervals.</li>
<li>Thus, the <code>getCurrentAcceleration</code> function will give you the last value reported from a Cordova <code>watchAccelerometer</code> call.</li>
</ul>
<hr>
<h1><a name="accelerometer.watchAcceleration">accelerometer.watchAcceleration</a></h1>
<p>At a regular interval, get the acceleration along the x, y, and z axis.</p>
<pre class="prettyprint"><code>var watchID = navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a>(<a href="cordova_accelerometer_accelerometer.md.html#accelerometerSuccess">accelerometerSuccess</a>,
<a href="cordova_accelerometer_accelerometer.md.html#accelerometerError">accelerometerError</a>,
[<a href="cordova_accelerometer_accelerometer.md.html#accelerometerOptions">accelerometerOptions</a>]);
</code></pre>
<h2>
<a name="accelerometer.watchAcceleration_description">Description</a>
</h2>
<p>The accelerometer is a motion sensor that detects the change (delta) in movement relative to the current position. The accelerometer can detect 3D movement along the x, y, and z axis.</p>
<p>The <code><a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a></code> gets the device's current acceleration at a regular interval. Each time the <code><a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a></code> is retrieved, the <code><a href="cordova_accelerometer_accelerometer.md.html#accelerometerSuccess">accelerometerSuccess</a></code> callback function is executed. Specify the interval in milliseconds via the <code>frequency</code> parameter in the <code>acceleratorOptions</code> object.</p>
<p>The returned watch ID references references the accelerometer watch interval. The watch ID can be used with <code><a href="cordova_accelerometer_accelerometer.md.html#accelerometer.clearWatch">accelerometer.clearWatch</a></code> to stop watching the accelerometer.</p>
<h2>
<a name="accelerometer.watchAcceleration_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 5.0 and higher)</li>
<li>iPhone</li>
<li>Windows Phone 7 (Mango)</li>
<li>Bada 1.2 &amp; 2.x</li>
</ul>
<h2>
<a name="accelerometer.watchAcceleration_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>function onSuccess(acceleration) {
alert('<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
};
function onError() {
alert('onError!');
};
var options = { frequency: 3000 }; // Update every 3 seconds
var watchID = navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a>(onSuccess, onError, options);
</code></pre>
<h2>
<a name="accelerometer.watchAcceleration_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Example&lt;/title&gt;
&lt;script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" charset="utf-8"&gt;
// The watch id references the current `watchAcceleration`
var watchID = null;
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
startWatch();
}
// Start watching the acceleration
//
function startWatch() {
// Update acceleration every 3 seconds
var options = { frequency: 3000 };
watchID = navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a>(onSuccess, onError, options);
}
// Stop watching the acceleration
//
function stopWatch() {
if (watchID) {
navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.clearWatch">accelerometer.clearWatch</a>(watchID);
watchID = null;
}
}
// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration) {
var element = document.getElementById('accelerometer');
element.innerHTML = '<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '&lt;br /&gt;' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '&lt;br /&gt;' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '&lt;br /&gt;' +
'Timestamp: ' + acceleration.timestamp + '&lt;br /&gt;';
}
// onError: Failed to get the acceleration
//
function onError() {
alert('onError!');
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="accelerometer"&gt;Waiting for accelerometer...&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<h2>
<a name="accelerometer.watchAcceleration_iphone_quirks"> iPhone Quirks</a>
</h2>
<ul>
<li>At the interval requested, Cordova will call the success callback function and pass the accelerometer results.</li>
<li>However, in requests to the device Cordova restricts the interval to minimum of every 40ms and a maximum of every 1000ms.
<ul>
<li>For example, if you request an interval of 3 seconds (3000ms), Cordova will request an interval of 1 second from the device but invoke the success callback at the requested interval of 3 seconds.</li>
</ul>
</li>
</ul>
<hr>
<h1><a name="accelerometer.clearWatch">accelerometer.clearWatch</a></h1>
<p>Stop watching the <code><a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a></code> referenced by the watch ID parameter.</p>
<pre class="prettyprint"><code>navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.clearWatch">accelerometer.clearWatch</a>(watchID);
</code></pre>
<ul>
<li>
<strong>watchID</strong>: The ID returned by <code><a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a></code>.</li>
</ul>
<h2>
<a name="accelerometer.clearWatch_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 5.0 and higher)</li>
<li>iPhone</li>
<li>Windows Phone 7 (Mango)</li>
<li>Bada 1.2 &amp; 2.x</li>
</ul>
<h2>
<a name="accelerometer.clearWatch_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>var watchID = navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a>(onSuccess, onError, options);
// ... later on ...
navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.clearWatch">accelerometer.clearWatch</a>(watchID);
</code></pre>
<h2>
<a name="accelerometer.clearWatch_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Example&lt;/title&gt;
&lt;script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" charset="utf-8"&gt;
// The watch id references the current `watchAcceleration`
var watchID = null;
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
startWatch();
}
// Start watching the acceleration
//
function startWatch() {
// Update acceleration every 3 seconds
var options = { frequency: 3000 };
watchID = navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.watchAcceleration">accelerometer.watchAcceleration</a>(onSuccess, onError, options);
}
// Stop watching the acceleration
//
function stopWatch() {
if (watchID) {
navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.clearWatch">accelerometer.clearWatch</a>(watchID);
watchID = null;
}
}
// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration) {
var element = document.getElementById('accelerometer');
element.innerHTML = '<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '&lt;br /&gt;' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '&lt;br /&gt;' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '&lt;br /&gt;' +
'Timestamp: ' + acceleration.timestamp + '&lt;br /&gt;';
}
// onError: Failed to get the acceleration
//
function onError() {
alert('onError!');
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="accelerometer"&gt;Waiting for accelerometer...&lt;/div&gt;
&lt;button onclick="stopWatch();"&gt;Stop Watching&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<hr>
<h1><a name="Acceleration">Acceleration</a></h1>
<p>Contains <code><a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a></code> data captured at a specific point in time.</p>
<h2>
<a name="Acceleration_properties">Properties</a>
</h2>
<ul>
<li>
<strong>x:</strong> Amount of acceleration on the x-axis. (in m/s^2) (<code>Number</code>)</li>
<li>
<strong>y:</strong> Amount of acceleration on the y-axis. (in m/s^2) (<code>Number</code>)</li>
<li>
<strong>z:</strong> Amount of acceleration on the z-axis. (in m/s^2) (<code>Number</code>)</li>
<li>
<strong>timestamp:</strong> Creation timestamp in milliseconds. (<code>DOMTimeStamp</code>)</li>
</ul>
<h2>
<a name="Acceleration_description">Description</a>
</h2>
<p>This object is created and populated by Cordova, and returned by an <code><a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a></code> method. The x, y, z acceleration values include the effect of gravity (9.81 m/s^2), so at when a device is lying flat on a table facing up, the value returned should be x=0, y=0, z=9.81.</p>
<h2>
<a name="Acceleration_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>BlackBerry WebWorks (OS 5.0 and higher)</li>
<li>iOS</li>
<li>Windows Phone 7 (Mango)</li>
<li>Bada 1.2 &amp; 2.x</li>
<li>webOS</li>
</ul>
<h2>
<a name="Acceleration_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>function onSuccess(acceleration) {
alert('<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
};
function onError() {
alert('onError!');
};
navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</a>(onSuccess, onError);
</code></pre>
<h2>
<a name="Acceleration_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Example&lt;/title&gt;
&lt;script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" charset="utf-8"&gt;
// Wait for Cordova to load
//
document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
navigator.<a href="cordova_accelerometer_accelerometer.md.html#accelerometer.getCurrentAcceleration">accelerometer.getCurrentAcceleration</a>(onSuccess, onError);
}
// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration) {
alert('<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
}
// onError: Failed to get the acceleration
//
function onError() {
alert('onError!');
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Example&lt;/h1&gt;
&lt;p&gt;getCurrentAcceleration&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<hr>
<h1><a name="accelerometerSuccess">accelerometerSuccess</a></h1>
<p>onSuccess callback function that provides the <a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> information.</p>
<pre class="prettyprint"><code>function(acceleration) {
// Do something
}
</code></pre>
<h2>
<a name="accelerometerSuccess_parameters">Parameters</a>
</h2>
<ul>
<li>
<strong>acceleration:</strong> The acceleration at a single moment in time. (<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a>)</li>
</ul>
<h2>
<a name="accelerometerSuccess_example">Example</a>
</h2>
<pre class="prettyprint"><code>function onSuccess(acceleration) {
alert('<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> X: ' + acceleration.x + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Y: ' + acceleration.y + '\n' +
'<a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a> Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
};
</code></pre>
<hr>
<h1><a name="accelerometerError">accelerometerError</a></h1>
<p>onError callback function for acceleration functions.</p>
<pre class="prettyprint"><code>function() {
// Handle the error
}
</code></pre>
<hr>
<h1><a name="accelerometerOptions">accelerometerOptions</a></h1>
<p>An optional parameter to customize the retrieval of the accelerometer.</p>
<h2>
<a name="accelerometerOptions_options">Options</a>
</h2>
<ul>
<li>
<strong>frequency:</strong> How often to retrieve the <code><a href="cordova_accelerometer_accelerometer.md.html#Acceleration">Acceleration</a></code> in milliseconds. <em>(Number)</em> (Default: 10000)</li>
</ul>
</div>
</div>
<!-- Functionality and Syntax Highlighting -->
<script type="text/javascript" src="index.js"></script><script type="text/javascript" src="prettify/prettify.js"></script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.