admin管理员组文章数量:1315318
I have code that is intended to measure device motion on a mobile device, and it used to work in mobile browsers, but no longer does. Here's an example taken directly from the Mozilla web docs:
function handleMotionEvent(event) {
var x = event.accelerationIncludingGravity.x;
var y = event.accelerationIncludingGravity.y;
var z = event.accelerationIncludingGravity.z;
// Do something awesome.
}
window.addEventListener("devicemotion", handleMotionEvent, true);
As far as I can tell, code like this no longer works in a mobile browser (circa Aug 2019).
Why? What needs to be done?
After spending time trying to debug my own code, I discovered that the many examples/demos/testers available on the web also no longer work, eg:
/
/
It seems that this is related to some changes in modern browsers/permissions/etc, perhaps related to recently revealed security issues related to accelerometer access, and steps being taken by Apple and Google as a result, eg:
/
What I found is that neither a recent Android phone running up to date Chrome nor a relatively recent iOS phone running Safari seem to allow webapp access to the motion sensors anymore. However, when I load the same demo code (eg from the above demo websites) on an older Android device... it works fine as it used to.
What needs to be done to access motion data within a webapp?
Thank you
I have code that is intended to measure device motion on a mobile device, and it used to work in mobile browsers, but no longer does. Here's an example taken directly from the Mozilla web docs:
function handleMotionEvent(event) {
var x = event.accelerationIncludingGravity.x;
var y = event.accelerationIncludingGravity.y;
var z = event.accelerationIncludingGravity.z;
// Do something awesome.
}
window.addEventListener("devicemotion", handleMotionEvent, true);
As far as I can tell, code like this no longer works in a mobile browser (circa Aug 2019).
Why? What needs to be done?
After spending time trying to debug my own code, I discovered that the many examples/demos/testers available on the web also no longer work, eg:
http://www.gianpa./shake/
http://www.albertosarullo./demos/accelerometer/
It seems that this is related to some changes in modern browsers/permissions/etc, perhaps related to recently revealed security issues related to accelerometer access, and steps being taken by Apple and Google as a result, eg:
https://www.macrumors./2019/02/04/ios-12-2-safari-motion-orientation-access-toggle/
What I found is that neither a recent Android phone running up to date Chrome nor a relatively recent iOS phone running Safari seem to allow webapp access to the motion sensors anymore. However, when I load the same demo code (eg from the above demo websites) on an older Android device... it works fine as it used to.
What needs to be done to access motion data within a webapp?
Thank you
Share Improve this question asked Aug 26, 2019 at 18:25 user2330237user2330237 1,7035 gold badges23 silver badges40 bronze badges2 Answers
Reset to default 8Apparently it is now required to serve and access a website/webapp using https:// for it to be able to use the motion sensors. I accessed the same URL above that didn't provide any sensor data using http://, and it did work using https://
If you have an older version of Chrome 63, please enable the chrome://flags/#enable-generic-sensor
flag.
If you are using environmental sensors, such as, Magnetometer or AmbientLightSensor, please also enable chrome://flags/#enable-generic-sensor-extra-classes
flag.
Reference: https://intel.github.io/generic-sensor-demos/
本文标签:
版权声明:本文标题:javascript - How do you access the motion sensors (accelerometer, gyroscope) in a mobile browser webapp inafter 2019? Why does i 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741977773a2408223.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论