Some Android apps generate a notification when the device’s volume changes and some lock the volume. For the life of me, I cannot find out how that’s done. Please, can someone help me by providing an example?
Some Android apps generate a notification when the device’s volume changes and some lock
Share
There is no Broadcast Action to detect volume changes, but you could maybe every second or two check what the volume is with
getStreamVolumeand if you need to lock it at a specific volume, every second or two use:setStreamVolumeCheck http://developer.android.com/reference/android/media/AudioManager.htm for more info.
You could use the AlarmManager class or a handler to check the volume every second or so.
If it’s an activity, you can override
onKeyDownto detect key presses. See http://developer.android.com/reference/android/view/View.html