Access accelerometer via Javascript in Android?

Jeff Lamb picture Jeff Lamb · Dec 17, 2010 · Viewed 34.3k times · Source

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.

Answer

Bamerza picture Bamerza · Jun 4, 2012

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.

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