标签:
3.0版本后,cordova通过插件模式实现设备API,使用CLI的plugin命令可以添加或者移除插件:
$ cordova plugin add org.apache.cordova.device-motion $ cordova plugin ls [ ‘org.apache.cordova.device-motion‘ ] $ cordova plugin rm org.apache.cordova.device-motion
<feature name="Accelerometer"> <param name="android-package" value="org.apache.cordova.devicemotion.AccelListener" /> </feature>
<feature name="Accelerometer"> <param name="android-package" value="org.apache.cordova.devicemotion.AccelListener" /> </feature>
<feature name="Accelerometer" value="Accelerometer" />
<feature name="Accelerometer"> <param name="ios-package" value="CDVAccelerometer" /> </feature>
<Capabilities> <Capability Name="ID_CAP_SENSORS" /> </Capabilities>
navigator.accelerometer.getCurrentAcceleration(accelerometerSuccess, accelerometerError);
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);
}
远程使用,要注意需要把plugins 等拷贝过去。
标签:
原文地址:http://www.cnblogs.com/aibo/p/4194788.html