Wednesday, June 3, 2015

Control Android's recent apps screenshot or disable screenshots in Android

Sometimes you have a situation when you need to control the screenshot that is shown in Android's task switcher / recents apps menu,



For example: you have an application with a lock screen, and when the user lock his session and the application moves to background, you don't want to accidentally show the last application activity in the recents apps menu.

Sooo, You have 2 options:
  1. Exclude your app from the recents apps menu
    You can do it by adding next code in the manifest.xml file under the <activity> tags:
     android:excludeFromRecents="true"

  2. Disable screenshots of your app
    You can disable screenshots of your app, and as a side effect, 
    The android system itself, won't be able to take a screenshot of your app last session.
    You can do it by:

    public class MyActivity extends Activity 
    {
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(LayoutParams.FLAG_SECURE,
                            LayoutParams.FLAG_SECURE);
        setContentView(R.layout.main);
      }
    }
    

    Please note that in this option, your app will still be in the recent apps menu, 
    but with a blank (white or black) screenshot thumbnail.

    In Addition, when you will try to get screenshot you will get this message:






1 comment:

  1. Hi David, what if we want the user to take screenshot but disallow the system? I tried a lot of solutions. Did you find anything else you can share?

    ReplyDelete