- // Remove the warning below that `getWindow()` might be null.
- assert alertDialog.getWindow() != null;
+ // Get the alert dialog window.
+ Window dialogWindow = alertDialog.getWindow();
+
+ // Remove the incorrect lint warning below that the dialog window might be null.
+ assert dialogWindow != null;
+
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+ // Get the screenshot preference.
+ boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);