Jayce
Jayce

Reputation: 842

Android exclude view from screenshot

So I have a service that runs an overlay view from my app (think like the facebook messenger icon). When you click on this it opens up another view that has some information on it. Is there a way to block that view only from showing when the user takes a screenshot on their device? I do not mean using getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); to stop screenshots all together, but just make that view invisible when a screenshot is taken?

Upvotes: 2

Views: 1004

Answers (3)

divyang4481
divyang4481

Reputation: 1783

Use SurfaceView inside your view so it will help you

Ref Link

Upvotes: 1

Vinay W
Vinay W

Reputation: 10190

If i understand the question correctly, you want to protect part of the content from screenshots, but not the whole window. As @CommonsWare suggests, it's not possible. But, there MIGHT be a (silly) solution, if you are desperate.

This solution may seem a bit impractical, and won't be applicable to your use case (or any use case) .. but here it is anyway

Maybe, you could show two windows (and hence, activities) - one with the sensitive content, one with the not-sensitive content (and use FLAG_SECURE on the sensitive window/activity)

How to display two activities at once?

  • Starting with N, Android supports a multi window mode (more than one activity, side by side)
  • You may be able to force an activity to launch in multi-window mode/switch to multi window mode after being launched.. using this technique ( pass AccessibilityService.html#GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN to AccessibilityService.html#performGlobalAction(int)) . Say, you launch the non-sensitive activity in this mode.
  • Once your non-sensitive activity is in split screen mode, you could launch the sensitive activity, also in split-screen mode using FLAG_ACTIVITY_LAUNCH_ADJACENT (this flag only works if the device is ALREADY in multi-window mode, which we might be able to achieve with AccessibilityService technique)

Disclaimer: I haven't tried this. Also, If it works, it will work with Android N and above, obviously. Hope it helps (probably wont, sorry :-) )

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006539

No, sorry — your choices are FLAG_SECURE for the window, or nothing. You are not informed when a screenshot is about to be taken to possibly do anything in response to it.

Upvotes: 1

Related Questions