ikaruga Posted July 27, 2021 Share Posted July 27, 2021 How do you guys do motion detection (if any) in your apps? Motion detection is when you detect when the user shakes their phone (for example). I just tried the following in Android Chrome to no avail: devicemotion event API. Supposedly it works on Chrome but it had no effect on my phones. See https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent. Interestingly, it did work on Firefox Focus this code snippet for cross-browser compatibility. Again, it did not work on Android Chrome. See https://stackoverflow.com/a/4378439/555493 the Gyroscope API. See https://developer.mozilla.org/en-US/docs/Web/API/Gyroscope Curious to see what people do to handle device motion. Currently, the best approach seems to be to use something like Flutter to shove device motion events into state, render the app into a Web view, and then query the motion state from the Web view as needed. Quote Link to comment Share on other sites More sharing options...
Exca Posted August 9, 2021 Share Posted August 9, 2021 I've been using device motion and gyroscope both. Are you running under https when testing? The api works (in chrome at least) only when it is requested on a site that is hosted on https. Also making sure that the device has required sensors is something that should be done. Also on apple you need a separate permission to use gyroscope data. Quote Link to comment Share on other sites More sharing options...
ikaruga Posted August 9, 2021 Author Share Posted August 9, 2021 Interesting. I've been following along tutorials online and running code locally. Hadn't noticed if these were running https. Will definitely try again :-) @Exca Quote Link to comment Share on other sites More sharing options...
ikaruga Posted August 11, 2021 Author Share Posted August 11, 2021 Yea @Exca that was the issue. Ran the code locally via https and it worked fine. To clarify, this was android mobile chrome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.