April 2016
Intermediate to advanced
194 pages
4h 37m
English
One of the most common use cases of the accelerometer sensor is to detect the shaking of the phone. Shaking can act as a valuable input for the apps, especially when the phone screen is off. For example, a lot of music player apps allow you to change the songs just by shaking the phone. In our example, we will play a small audio MP3 file when the phone shake is detected using the accelerometer sensor:
ShakeDetectionActivity and follow the standard steps for getting values from a sensor. We will select the sensor type for TYPE_ACCELEROMETER in the getDefaultSensor() ...