Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I program various android powered phone buttons to launch my app?

I have a requirement in my app where I have to select various buttons like Search, Volume Up, Volume Down, Back buttons to launch my app.

enter image description here

I know that I have to override the functionality of the these buttons but what API do I have to use and exactly how can I override them.

like image 595
Muhammad Maqsoodur Rehman Avatar asked Nov 11 '22 14:11

Muhammad Maqsoodur Rehman


1 Answers

Your application should be running and you need this code:

public boolean onKeyDown(int keyCode, KeyEvent event) 
{ 
   if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { 
       // Do your thing 
       return true;
   } else {
       return super.onKeyDown(keyCode, event); 
   }
}

List of keys: http://developer.android.com/reference/android/view/KeyEvent.html

like image 86
72DFBF5B A0DF5BE9 Avatar answered Jan 04 '23 02:01

72DFBF5B A0DF5BE9