tags:

views:

162

answers:

2

I would like to detect when the phone is in motion, but not all kind of motion. For example picking up or waving the phone should not trigger.

I would like ideally to run a code when the phone/person is in > "walking" state. What options I have?

A: 

You can also get your location from Wifi-Networks and Cell Towers. All location providers in Android are subclasses of android.location.LocationProvider. That's probably a good place to start. I don't know that either of those would be best for you, as their "range" can be several hundreds of feet wide.

Ryan Hayes
Are they offering some kind of `speed`? as I am looking to get the speed, not the location change.
Pentium10
Hmm, I don't know about speed straight from it, I haven't looked that far. I guess you could poll twice, and then calculate distance/time=speed.
Ryan Hayes
That method is very bad because cell tower locations should only be used for localisation in things like weather apps or where broad/general locations are required. Just try Google maps with GPS off and see for yourself
HXCaine
Yea, that would really only work if you were driving from city to city. Definitely shouldn't be used for fined grained location.
Ryan Hayes
+1  A: 

you can use a combination of the accelerometer and the digital compass, in phones that have them, to determine a speed and direction.

If all you need to do is determine if the person is walking, all you need is the accelerometer. Just process its output for foot steps.

There are plenty of tutorials on the web for detecting foot steps with an accelerometer.

Mark
Can you pin-point at least one tutorial?
Pentium10
There an app note here: http://www.analog.com/library/analogDialogue/archives/41-03/pedometer.htmlthat gives a decent mathematical background and an example algorithm. Its of course up to you to extract the math and rewrite it for Android (the example code is written in C). I don't currently know of an open source android library with a footstep detection algorithm.
Mark
Also note that if all you want to know is if the person is walking or not, you don't need to go through all the work of detecting each step and determining stride length. Likely you can create some basic metric for "walking" vs "not walking". Something like, if the total acceleration is over X in any time period Y we are walking/running. It should be reasonably accurate unless the person loves to violently shake their phone for 30sec at a time.
Mark