Reputation: 1132
I would like to hide content of my android app in the app preview mode. I am referring to the view you see when switching between apps.
The following window settings hides the content but it also disables the ability to take screenshots of the app which I don't want
activity.Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
Is there a setting I could use to hide the app content but still allow the user to take screen shots?
Here is an example of the app preview where the content isn't hidden
Upvotes: 0
Views: 417
Reputation: 199
For platforms Android 8.0 and newer(>= SDK 26), to make the screen blank in recent list and still allow screen you can set the flag in onPause() and clear the flag in onResume(). To make it common for all activities, in Application class register an Application.ActivityLifecycleCallbacks and add following lines inside specific overridden functions. You may try this:
fun onActivityResumed(activity: Activity) {
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
fun onActivityPaused(activity: Activity) {
activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
Upvotes: 1