5

I'm currently developing a light-weight application where in one part of the app I would like to COMPLETELY take away the ability to take a screenshot in Android. When I say screenshot, I'm talking about iPhone's "screen capture" feature. This is for security reasons. I realize there are apps out there that allow users in Android to do this as well, and I want to block this functionality. Any way of doing this is fine, whether disabling the hardware buttons, freezing the phone, or via software.

Charles
  • 50,943
  • 13
  • 104
  • 142
datWooWoo
  • 843
  • 1
  • 12
  • 42
  • 2
    For ICS and up, have you tried [this](http://commonsware.com/blog/2012/01/16/secure-against-screenshots.html)? For everything older, mileage will vary since there wasn't a standard screenshot implementation. – A--C Aug 22 '13 at 23:40

2 Answers2

3

You can use the window LayoutParam FLAG_SECURE. Add this to your onCreate method:

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}

More on this topic can be found here.

Community
  • 1
  • 1
Phil
  • 35,852
  • 23
  • 123
  • 164
0

Add an application class in your project like that to prevent the full app from screen-shot (All Activity and Fragment around your app). This is the example project and below I mentioned the core code -

public class MyApplicationContext extends Application {

    private  Context context;

    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        setupActivityListener();
    }

    private void setupActivityListener() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);            }
            @Override
            public void onActivityStarted(Activity activity) {
            }
            @Override
            public void onActivityResumed(Activity activity) {

            }
            @Override
            public void onActivityPaused(Activity activity) {

            }
            @Override
            public void onActivityStopped(Activity activity) {
            }
            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
            }
            @Override
            public void onActivityDestroyed(Activity activity) {
            }
        });
    }
}
Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42