Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

android broadcastreceiver for volume key up and down using -'android,android-intent,volume'


android broadcastreceiver for volume key up and down  using -'android,android-intent,volume'

If a user presses volume key up or down is it possible to detect it in my broadcast receiver? I need the full code.

Here is my Intent filter

IntentFilter filter = new IntentFilter();
filter.addAction("android.media.VOLUME_CHANGED_ACTION");


and my onReceive method is

public void onReceive(Context arg0, Intent intent) {
      KeyEvent ke = (KeyEvent)intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
        if (ke .getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
                System.out.println("I got volume up event");
         }else if (ke .getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
                System.out.println("I got volume key down event");
         }
    }


It gives me a null KeyEvent... any idea?
    

asked Sep 7, 2015 by rajesh
0 votes
82 views



Related Hot Questions



Government Jobs Opening


...