Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent screen capture in Android apps

I was wondering if there is a way to detect through some "onXXXXX" call-back method or received broadcast if some other process is about to take a screen-shot of my app's display. For example if the SDK tools or some other screen capturing app performs a "Screen Capture", I would like to be notified and then decide if I should allow or disallow the screen capture.

If this is not possible is there a way to lock the display so no other process can screen capture my display?

like image 738
burgwindeck Avatar asked Jul 20 '11 15:07

burgwindeck


People also ask

How do you stop apps from Screenshotting?

In the MainActivity. java file simply add the following code and it will prevent taking Screenshot in Android App. getWindow(). setFlags(WindowManager.

Is it possible to prevent screen capture?

So, we can't prevent users from taking screenshots. Besides all these things if the user wants to get the content of our webpage, they can copy it, print it, use some third-party applications or take a picture of it using some other devices.

Can an app restrict screenshot?

Open the Restricted app where you want to take the screenshot. Click on the floating button on your screen, and select the Settings icon that looks like a toolbox. Enable the Screenshot option from the list and close the list.


2 Answers

This worked for me on a Samsung Tab 2 7"

Using the following approach, to simply add the FLAG_SECURE to the Window Flags

public class FlagSecureTestActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFlags(LayoutParams.FLAG_SECURE,
                         LayoutParams.FLAG_SECURE);

    setContentView(R.layout.main);
  }
}

with the caveat that you may need to change

LayoutParams

to

WindowManager.LayoutParams
like image 104
user330844 Avatar answered Oct 23 '22 18:10

user330844


There is no supported method to take a screenshot of another app on Android. The only ways involve either rooting or using the SDK, which both offer little to no chance of you either blocking or receiving notification of it. If another app takes your screenshot, it is by default using non-supported methods and can probably do as it pleases.

I'd like to clarify that I am not implying you shouldn't use any methods available to secure your app. I'm just letting you know that it is probably impossible to do so without using non-supported methods, and that even if you do use them you may not be 100% secure against screenshots.

like image 38
jakebasile Avatar answered Oct 23 '22 18:10

jakebasile