Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLAG_SECURE not working on libgdx's AndroidApplication

Tags:

android

libgdx

I have an Android game created with help of libGDX. I want to disable the ability to take screenshots.

For regular android activities you can use getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); method. It works fine.

But it doesn't work with activities extended from com.badlogic.gdx.backends.android.AndroidApplication. I'm still able to take screenshots.

Any ideas?

like image 261
alan_derua Avatar asked Apr 26 '26 15:04

alan_derua


1 Answers

Calling initialize in AndroidApplication sets up the window parameters for a full-screen game, so it's overwriting your window parameters. So instead, put this in onCreate after you call initialize. Note that you should use addFlags instead of setFlags so you don't mess up the other flags that Libgdx set.

getWindow().addFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
like image 145
Tenfour04 Avatar answered Apr 29 '26 03:04

Tenfour04