Shyam
Shyam

Reputation: 881

How to override zoom buttons of camera in an android app?

I'm having zxing app for barcode scanning. It's having auto-focus but i need to set zoom in/out in my app.

It will be better if i can override volume control buttons in android device for zooming in the app.

How can i implement zooming in my app using volume control buttons?

Please share your thoughts..

Upvotes: 0

Views: 1184

Answers (3)

ksu
ksu

Reputation: 902

Try to use dispatchKeyEvent by putting the following code in your activity.

      public boolean dispatchKeyEvent(KeyEvent event) {
        int keyCode = event.getKeyCode();
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            addIntensityLvl();
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            subtractIntensityLvl();
                return true;
        default:
            return super.dispatchKeyEvent(event);
        }
    }

Upvotes: 0

Shankar Agarwal
Shankar Agarwal

Reputation: 34775

public boolean onKeyUp(int keyCode, KeyEvent event) 
{ 
   if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { 
       // increase your zoom
       return true;
   } else if(keyCode ==  KeyEvent.KEYCODE_VOLUME_UP){
       // decrease your zoom 
       return true;
   }
   return super.onKeyUp(keyCode, event); 
}

you can use the above onKeyUp() event to do you task:::

Upvotes: 1

Tim
Tim

Reputation: 35943

See here for how to override the volume control buttons. You can perform zoom when you capture the event.

Upvotes: 0

Related Questions