Udi Oshi
Udi Oshi

Reputation: 6867

onKeyDown has not been called when popupwindow is visible

I'm using the following function (in Activity) to detect volume buttons clicks:

    @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP){
        if(mAudioManager != null){
            int curVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
            Intent intent = new Intent();
            intent.setAction(VerticalSeekBar.ACTION_VOLUME_CHANGED);
            intent.putExtra(VerticalSeekBar.ARGUMENT_VOLUME_VALUE,curVolume);
            sendBroadcast(intent);
            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

Thing is I have popupwindow which represents volume bar as Vertical seek bar in it's view. when the popupwindow is shown the onKeyDown in my activity is not being called untill I dimissed the popupwindow.

any suggestion how to solve this issue? is there another way to detect volume buttons clicks? thanks very much for the help

Upvotes: 1

Views: 984

Answers (2)

Orgazm pionerki
Orgazm pionerki

Reputation: 366

Try set focusable false for your PopupWindow class.

mMyPopupWindow.setFocusable(false);

Upvotes: 4

Nicklas Gnejs Eriksson
Nicklas Gnejs Eriksson

Reputation: 3415

Not sure how you are actually using that Popup but if you use a Dialog instead you have access to the onKeyDown(); for the Dialog.

http://developer.android.com/reference/android/app/Dialog.html#onKeyDown%28int,%20android.view.KeyEvent%29

Upvotes: 0

Related Questions