Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch App on clicking power and volume up button in Android

Tags:

android

I want to launch my app on pressing power and volume up button together. I am able to launch the app on volumeChange but the default increase/decrease of volume functionality is overrided. So, Can anyone let me know how to do with the combination of two buttons?

I am launching the app this way, which works fine.

Intent i = new Intent();
i.setClass(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

Need help to handle on pressing keys event.

Thanks, Adheesh.

like image 793
Adheesh Avatar asked Jan 22 '26 17:01

Adheesh


1 Answers

I've used this code to listen for the volume button before.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)){
        //Do something
    }
    return true;
}
like image 170
Mohammed Mahmoud Avatar answered Jan 24 '26 08:01

Mohammed Mahmoud