Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I programmatically access a smartphone's sensors through the browser and JavaScript?

Is it possible for me to programmatically access a smartphone's sensors (e.g. accelerometer, compass, etc. on an Android or iPhone device) through a browser webpage and JavaScript? I know that the W3C Devices standard can allow access to the camera.

like image 977
stackoverflowuser2010 Avatar asked Nov 15 '22 03:11

stackoverflowuser2010


1 Answers

HTML5 is likely to contain a sensor API. Until this is fully standardized, vendors provide their own APIs such as Apple does for mobile Safari.

There's no need for full blown solutions like PhoneGap or similar if it is Ok for you to restrict yourself to a specific vendor/device. If not, frameworks like PhoneGap provide you with a unified, device independent API.

You should be aware of the Performance constraints that apply to Javascript applications running inside the browser of a mobile device. Depending on your type of application and the amount of processing you intend to do on the sensor data, you are better off writing a native application

See https://developer.apple.com/library/safari/iPad/#documentation/SafariDOMAdditions/Reference/DeviceMotionEventClassRef/DeviceMotionEvent/DeviceMotionEvent.html for some reference documentation.

like image 59
Johannes Rudolph Avatar answered Nov 16 '22 15:11

Johannes Rudolph