Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?). Anyways, using some code along the lines of the following I can do this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyUp(keyCode, event);
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
    //this is where I can do my stuff
    return true; //because I handled the event
}
return false; //otherwise the system can handle it        

}

But I would like it to be possible even when the application is not open, hence why I'd like to set up a broadcast receiver or maybe stick something in a service to make this possible.

Thanks for any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
314 views
Welcome To Ask or Share your Answers For Others

1 Answer

as well as the screen on/off button - is this possible?

Fortunately, no.

But I would like it to be possible even when the application is not open, hence why I'd like to set up a broadcast receiver or maybe stick something in a service to make this possible.

This is not possible for the volume buttons.

For example, AndroSS allows you to override the camera hardware button to take a screenshot.

That is the camera button. If the foreground activity does not consume a camera button click, that gets turned into a broadcast Intent, which other applications can listen for. This behavior is unique to the camera and media buttons and is not used with any other hardware buttons.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...