Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLAG_SECURE not working on DialogFragment with style as DialogFragment.STYLE_NO_TITLE

When I set the style of a dialog fragment, the android is allowing to take the screen shot of dialog fragment, but after removing the style it works.

Below is the code of dialog fragment's onCreate

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light);
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    setCancelable(false);
}

Has any one else faced a similar issue before?

like image 776
bakriOnFire Avatar asked Dec 09 '25 09:12

bakriOnFire


1 Answers

AFAICT, using FLAG_SECURE on the hosting activity is insufficient to make a DialogFragment secure.

In addition to using FLAG_SECURE for the activity, call getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); on the Dialog that you create in onCreate() of the DialogFragment, before you return that Dialog.

like image 146
CommonsWare Avatar answered Dec 11 '25 23:12

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!