Cha*_*son 1 javascript android cordova
我正在尝试访问我的Cordova [3.3.1-0.1.2] Android应用程序中的navigator.accelerometer,并且在Android [4.0.3]模拟器中运行时,navigator.accelerometer未定义.
我在设置Cordova应用程序时遵循了本教程:http://www.techariv.in/2013/08/creating-android-hello-cordova.html
我在www/config.xml里面添加了以下内容<widget>:
<plugin name="Accelerometer" value="org.apache.cordova.AccelListener" />
Run Code Online (Sandbox Code Playgroud)
我也试过了
<plugin name="Accelerometer" value="CDVAccelerometer" />
Run Code Online (Sandbox Code Playgroud)
另外,我在www/js/index.js中有以下内容(它确实加载了一个执行):
onDeviceReady: function() {
app.receivedEvent('deviceready');
alert(navigator.accelerometer);
navigator.accelerometer.getCurrentAcceleration(function() {
alert('success');
}, function() {
alert('fail');
});
},
Run Code Online (Sandbox Code Playgroud)
当应用程序运行时,我会收到一条简单说"未定义"的警报.不会调用getCurrentAcceleration()的回调.
请注意,onDeviceReady()是通过调用的
document.addEventListener('deviceready', this.onDeviceReady, false)
Run Code Online (Sandbox Code Playgroud)
(这是标准的"Hello World"应用程序,除了添加警报和加速度计回调之外没有任何修改.
| 归档时间: |
|
| 查看次数: |
3339 次 |
| 最近记录: |