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