Listen to volume buttons in background service?
问题 I know how to listen to volume buttons in an activity. But can I do that in a background service? If yes, how to do that? 回答1: Judging by the couple of other questions about this topic, no. Other question 1, Other question 2 Services simply do not receive KeyEvent callbacks. 回答2: It is possible. Use code below (for newer Android versions, especially Marshmallow, see bottom of the answer): public class SettingsContentObserver extends ContentObserver { int previousVolume; Context context;