Android – prevent screen capture in Android apps

androidscreenshot

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?

Best Answer

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