Amplifier to increase the volume in the Android receiver?

I'm trying to create an application in which the user can override the default behavior of the volume up / down buttons (as well as the screen on / off buttons - is this possible?). In any case, using some code in 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, so I would like to set up a broadcast receiver or perhaps use something in the service to make this possible.

Thanks for any help.

+4
source share
4 answers

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

Fortunately not.

But I would like this to be possible even when the application is not open, so I would like to set up a broadcast receiver or perhaps use something in the service to make this possible.

This is not possible for volume buttons.

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

This is the camera button. If the front does not use the camera button, it turns into an Intent broadcast that other applications can listen to. This behavior is unique to camera and media buttons and is not used with other hardware buttons.

+2
source

This is not a good idea. this means that every time you press the volume up / down keys, you will capture them no matter where you are. What if I want to change the ringer volume? media volume? an application that uses rockers for other purposes? it just won't work and just make people worse. plus, I'm not sure if this is doable.

0
source

This is impossible (easy) because the onKeyDown method overrides Activity.onKeyDown (). For this reason, you must have a foreground function to receive these function calls.

I have no experience with this, but you will have to dig deeper into writing your own hardware key intercept / handler functions, since you will not be able to access one of the activity class.

0
source

This probably won't do what you want, but if you create an IME, the IME can grab the +/- volume buttons and do whatever it wants, like reassigning other button presses. For example, I changed the Gingerbread-style IME to turn the +/- volume buttons to make the page up / down in the Kindle and Overdrive apps.

0
source

All Articles