Domanda

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

È stato utile?

Soluzione 2

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

Altri suggerimenti

Try set focusable false for your PopupWindow class.

mMyPopupWindow.setFocusable(false);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top