4

I want to make view solid white or black in recent apps screen but don't want to hide it completely. And also I want to enable screenshot feature without affecting user experience.

I saw the same implemented in whatsapp when fingerprint lock is enabled(beta apk). Anyone here having any idea about how that is implemented?

Please don't mark it as duplicate because following threads did not answer my question

Hide screen in 'Recent Apps List', but allow screenshots,

Question 2,

Android: Customizing recent apps thumbnail (screenshot by default)

Sanket Bhat
  • 340
  • 3
  • 16

1 Answers1

0

After a lot of investigation I came up with following conclusion

Android 7.0 or older(<= SDK 25):

Currently it is impossible to achieve this and there are no direct callbacks before system actually takes screenshot of the layout.

Android 8.0 and newer(>= SDK 26):

Anyhow adding secure layout flag to window in onPause() and clearing it in onResume() will work exactly as expected.

To make it common for all activities, In Application class register an Application.ActivityLifecycleCallbacks and add following lines inside specific overridden functions.

fun onActivityResumed(activity: Activity) {
    activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

fun onActivityPaused(activity: Activity) {
    activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
Sanket Bhat
  • 340
  • 3
  • 16
  • 2
    Didn't work me, tried this approach on Android 8, and Android 10 devices. AFAIK these flags will only work if you set them before calling the Activity's `setContentView()` in the `onCreate()`. – 4gus71n Jul 28 '20 at 13:57