I would take a look at how to read the accelerometer or gyroscope, to do this. I'm not really sure if this works or not, but that's how I would start out. Here's a link on how to use the accelerometer data.
http://www.techrepublic.com/blog/app-builder/a-quick-tutorial-on-coding-androids-accelerometer/472