Detecting support for device movement / orientation?

I am looking for a way to check if a device supports DeviceOrientationEvent or DeviceMotionEvent. To be more precise, I do not know if the device really has an accelerometer .

Unfortunately, window.DeviceMotionEvent and window.ondevicemotion respectively window.DeviceOrientationEvent and window.ondeviceorientation exist, although the device - MacBook Retina - does not have an accelerometer.

It is clear to me that if an event never fires, the eventlistener callback function will never fire either. But in my case, I, my program should know if the device has an accelerometer, because the user should receive a notification if there is no accelerometer.

The answers to this post, unfortunately, did not help my problem.

+6
source share
1 answer

Given that your program must have accelerometer functionality, I assume that you will block its execution if it is not.

That way, your program can block by default and listen on one MotionEvent device, which initializes your entire program, which will eventually be bound to window.ondevicemotion. This way you do not need to block execution with setTimeout; The MotionEvent device will most likely start quite quickly after the window loads.

+2
source

Source: https://habr.com/ru/post/969339/


All Articles