在 Android 中通过 Javascript 访问加速度计? [英] Access accelerometer via Javascript in Android?

查看:18
本文介绍了在 Android 中通过 Javascript 访问加速度计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Android 浏览器上使用 Javascript 访问加速度计数据?我知道它支持onorientationchange",但我想得到一切.

Is there any way to access accelerometer data using Javascript on Android's browser? I know it supports "onorientationchange", but I'd like to get everything.

澄清:我问的是如何在网站中执行此操作,而不是本机应用程序.

Clarification: I'm asking how to do this in a website, not a native app.

推荐答案

从 ICS、Android 4.0 开始,您可以通过 JavaScript 事件侦听器使用 'devicemotion' 事件来访问加速度计数据.请参阅有关如何访问它的 W3C 文档 - http://dev.w3.org/geo/api/spec-source-orientation.html.

As of ICS, Android 4.0, you can use the 'devicemotion' event via a JavaScript event listener to access the accelerometer data. See the W3C documentation on how to access it - http://dev.w3.org/geo/api/spec-source-orientation.html.

注意 - W3C 文档标题以设备方向"命名,但该规范确实包含devicemotion"事件文档.

Note - The W3C documentation title is named with 'device orientation', but the spec does indeed include 'devicemotion' event documentation.

这篇关于在 Android 中通过 Javascript 访问加速度计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆