Android capturing volume up/down key presses in broadcast receiver?

后端 未结 4 1186
感动是毒
感动是毒 2020-12-06 21:13

I\'m trying to make an application where the user can override the default behaviour of the volume up/down buttons (as well as the screen on/off button - is this possible?).

4条回答
  •  青春惊慌失措
    2020-12-06 21:38

    This is not (easily) possible, because the "onKeyDown" method is overriding Activity.onKeyDown(). For this reason, you have to have a foreground activity to receive these function calls.

    I don't have any experience doing this, but you would have to dig a bit deeper into writing your own hardware key intercept/handler functions, since you wouldn't be able to access the one from the activity class.

提交回复
热议问题