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?)?
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.