any way to detect volume key presses or volume changes with android service?

前端 未结 4 1850
忘了有多久
忘了有多久 2020-12-09 14:14

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 s

4条回答
  •  爱一瞬间的悲伤
    2020-12-09 14:36

    There is no Broadcast Action to detect volume changes, but you could maybe every second or two check what the volume is with getStreamVolume and if you need to lock it at a specific volume, every second or two use: setStreamVolume

    Check 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 onKeyDown to detect key presses. See http://developer.android.com/reference/android/view/View.html

提交回复
热议问题