SetVolumeControlStream does not work when a popup is displayed

I have this.setVolumeControlStream(AudioManager.STREAM_MUSIC); at the beginning of all the actions in my application, so when the user presses the volume up or down buttons, he controls the volume of the multimedia.

I have a popup in my program, and when this appears, the user can no longer manage the volume.

If you look at such questions, it seems that setting onKeyup/down listeners can interfere with the process - but I haven't set any - the only listeners I have for the popup are setOnClickListeners for buttons and setOnDismissListener for the window.

How can i fix this?

+6
source share
4 answers

I created a popup with

 my_popup_window = new PopupWindow(layout, x, y, true); 

Then I change it to this ...

 my_popup_window = new PopupWindow(layout); my_popup_window.setWidth(x); my_popup_window.setHeight(y); 

and the volume control started working again. I don’t understand why, but it worked.

0
source

It looks like you need to call setOwnerActivity for the Dialog object.

Method documentation:

Sets the action to which this dialog box belongs. Usage example: this dialog will use the proposed Activity Volume Management Flow.

While not tested, this should do the trick. There is also the option to use setVolumeControlStream .

+1
source

I just do this pop.setFocusable(false) . and it worked.

0
source

although Mick’s answer didn’t work for me, this is for posterity.

 //Declaration PopupWindow mWindow; ... //Constructor mWindow = new PopupWindow(context); ... //Prepare to Show mWindow.setContentView(); mWindow.setBackgroundDrawable(); mWindow.setFocusable(false); ... 

setting setFocusable to false helped my activity capture onKeyDown() again.

0
source

Source: https://habr.com/ru/post/911938/


All Articles