1

I am using the volume up/down buttons to navigate in an activity. This works fine but i cannot use the volume down button to start the next activity. Also the volume is simultaneously increased/reduced. Here is the code

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
 switch(keyCode){
     case KeyEvent.KEYCODE_VOLUME_DOWN:
         event.startTracking();
         //navigation


     return true;
     case KeyEvent.KEYCODE_VOLUME_UP:
         //navigation

     return true;
   }


   return super.onKeyUp(keyCode, event);
}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        startActivity(new Intent("com.example.fittle.FISH"));
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}
Deb
  • 33
  • 5

2 Answers2

0

try this little modified method:

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
     super.onKeyLongPress(keyCode, event);
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
    startActivity(new Intent("com.example.fittle.FISH"));
    return true;
}
return false;
}
Palejandro
  • 2,092
  • 5
  • 26
  • 38
0

You are using Intent in the wrong way, try change:

startActivity(new Intent("com.example.fittle.FISH"));

To

startActivity(new Intent(context, FISH.class));

Context can be this if you are calling it from activity.

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
  • @GopalRao As I understand from [Android](http://developer.android.com/guide/components/intents-filters.html), it is generally used to send commands to different applications. And it requires you to add a proper filters in manifast – Ilya Gazman Jan 02 '14 at 10:31
  • This is not the problem. I have changed the Intent but still it doesnot works. – Deb Jan 02 '14 at 20:22