Cordova,phonegap Gravity sensor

Source: Internet
Author: User
Tags configuration settings



After version 3.0, Cordova implements the device API via plug-in mode, and the CLI's plugin command allows you to add or remove plugins:


$ cordova plugin add org.apache.cordova.device-motion
    $ cordova plugin ls
    [ ‘org.apache.cordova.device-motion‘ ]
    $ cordova plugin rm org.apache.cordova.device-motion
This command can be applied to all platforms, but modifying platform-specific configuration settings requires the use of the following methods
  • Amazon Fire OS (in Res/xml/config.xml)
    <feature name="Accelerometer">
        <param name="android-package" value="org.apache.cordova.devicemotion.AccelListener" />
    </feature>
  • Android (in Res/xml/config.xml)
    <feature name="Accelerometer">
        <param name="android-package" value="org.apache.cordova.devicemotion.AccelListener" />
    </feature>
  • BlackBerry 10 (in Www/config.xml)
    <feature name= "Accelerometer" value= "Accelerometer"/>
  • IOS (in the application name of the config file)
    <feature name="Accelerometer">
        <param name="ios-package" value="CDVAccelerometer" />
    </feature>
  • Windows Phone (in Properties/wpappmanifest.xml)
    <Capabilities>
        <Capability Name="ID_CAP_SENSORS" />
    </Capabilities>
functionAccelerometer.getcurrentaccelerometer ()gets the acceleration in the leading X, y, and z directions.
Navigator.accelerometer.getCurrentAcceleration (accelerometersuccess, accelerometererror);
DescriptionThe accelerometer is a motion sensor that detects changes in the x/y/z direction of the device in three-dimensional space relative to the previous moment. These values are returned by the arguments passed to accelerometersuccess back to the function. Simple example
function onSuccess (acceleration) {
     alert (‘Acceleration X:‘ + acceleration.x + ‘\ n’ +
           ‘Acceleration Y:‘ + acceleration.y + ‘\ n’ +
           ‘Acceleration Z:‘ + acceleration.z + ‘\ n’ +
           ‘Timestamp:‘ + acceleration.timestamp + ‘\ n’);
};

function onError () {
     alert (‘onError!’);
};
document.addEventListener ("deviceready", onDeviceReady, false);
function onDeviceReady () {
         navigator.accelerometer.getCurrentAcceleration (onSuccess, onError);
     }

For remote use, pay attention to the need to copy plugins and so on. 


Cordova,phonegap Gravity sensor


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.