Detecting Significant Device Motion on Android

让人想犯罪 __ 提交于 2019-12-12 10:57:02

问题


I've been trying to figure out how to make an application that detects whether the device has been moved a significant amount, something more than just shakes. I am trying to detect a distance of, say, at least a foot. Reading the Training section on the official Android Development site, my best guess is that I should be using the Significant Motion Sensor, but I can't find an example of how to use it. Do I just store my "current" location in an array, and then compare that versus the Event's values array whenever there is an onTrigger() is called?

Or should I be using the accelerometer instead? Some other sensor? The LocationManager (is that one accurate enough?)?


回答1:


Based on the Significant Motion Sensor demo activity in ApiDemos, there isn't much to do. The triger sensor fires, contains no meaningful data in the values field (it's an array with just one element, always 1.0 according to what I've tested) and disables itself.

So, there is nothing to actually compare with. The event fired, and that's it. You'll just have to trust that it matches your definition of "moved a significant amount" :/

If you want to measure a distance on the order of a foot, I'm pretty sure Location isn't precise enough (since it's GPS based at most).

As for Accelerometer data, you could theoretically, calculate distance from it (acceleration -> speed -> distance) but it's highly inaccurate. See this answer, which basically claims it's not practical.



来源:https://stackoverflow.com/questions/24567399/detecting-significant-device-motion-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!