Secure Against Screenshots

Ice Cream Sandwich now allows the user to capture screenshots of the contents of the device screen, by simultaneously pressing the Power button and the Volume Down button.

(which, in practice, seems to be a lot harder than you might think…)

This has been an oft-requested feature, so it will make many users happy.

Note that this is not available via the SDK, so malware should not be able to screen-capture arbitrary stuff in your app. However, for the user’s benefit, there may be reasons to block screenshots from certain of your activities.

To do that, use FLAG_SECURE :

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); } }

Normally, when a user takes a screenshot, a Notification will be raised to indicate success and provide access to the screenshot in the Gallery app. With FLAG_SECURE in place, the Notification will be “Couldn’t capture screenshot”.

Want an expert opinion on your Android app architecture decisions? Perhaps Mark Murphy can help!

— Jan 16, 2012