You probably need to look at how to use the motion sensors in Android, particularly the rotation sensor. How accurate you want it to be depends on how many axes you are willing to consider and how good you are at math.
A detailed answer can be found here: How to detect left and right tilt of an android device mounted with an accelerometer?
0
solved How to make “tilt phone” action? Android App