Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to capture long press volume down key in android?

Tags:

android

Just wondering whether anyone could tell me how to capture the long keypress of the volume down key in android.

Elaborated question:

I wanted to create a BroadcastReceiver which will receive volume long keypress event. (without any UI interaction). I know it's possible for the search button. is it available for the Volume Keys?

Thanks

like image 314
kakopappa Avatar asked Mar 11 '11 06:03

kakopappa


People also ask

How do you lock volume buttons?

To turn off the volume buttons on your phone, go to Settings > Sounds and vibrations > Volume and select the "Media only" option. This will ensure the volume buttons only control media volume and not others like ringtone volume or alarm volume.

What does holding the volume down and power button do?

Press and hold the Volume Down and Power buttons simultaneously until the device turns on. You can use Volume Down to highlight Recovery Mode and the Power button to select it. Depending on your model, you may then have to enter your password and choose a language to enter recovery mode.

How do I fix my volume button on my Android?

Go to Settings >> Accessibility >> Accessibility menu. There are some apps that have been created to virtually replace your volume button. You can download a virtual volume button application from Play store. Just go to Play store and search for volume button, download and install an app that meets your needs.


1 Answers

may be below code will help you:

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
     // to your stuff here
     return true;
  }
  return super.onKeyLongPress(keyCode, event);
}
like image 151
ingsaurabh Avatar answered Oct 15 '22 00:10

ingsaurabh