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

前端 未结 4 1555
梦如初夏
梦如初夏 2021-01-18 16:22

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 Jav

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 17:12

    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.

提交回复
热议问题