FLAG_KEEP_SCREEN_ON not working when showing an alert dialog on wear os

447 views Asked by At

I am developing an Wear OS App, that requires to have the screen always on for certain tasks.

To achieve that, I use window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

It is working fine, but when I show an Dialog, the screen turns off after a few seconds.

I do not want to increase the timeout , but instead I need to keep the screen on while the dialog is showing on the screen.

I tried to use android:keepScreenOn="true" on my activity and it's working fine until I show Dialog.

There is how I create dialog.

val binding = ProgressLayoutWithTextBinding.inflate(LayoutInflater.from(context))
val dialog = Dialog(context)

binding.textProgress.text = message

dialog.setCancelable(false)
dialog.setContentView(binding.root)
dialog.show()

I'm using galaxy watch 4 (SM-R880)

Has anyone encountered this problem on a watch?

1

There are 1 answers

1
VisaJE On

Yes, I've had this problem. Solved it by

dialog.show()
dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)