Disabling screen shot capture in Android application

person folder_openAndroidaccess_time June 18, 2015

In this tutorial we are going to show how to protect your application from screen shot capturing. Some applications might be having sensitive personal data (for example all banking applications), so as a developer we need to disable the option to take screen shot using DDMS console.

See following steps :

  1. Use WindowManager.LayoutParams.FLAG_SECURE before setContentView() mehtod

Note: There is no application level protection. You have to add this code in all the activities that you want to protect.

Generally, when you take a screenshot, you will see a “Screen Capture” notification in the notification bar and you can see that screenshot in the Gallery app if you click that notification. Now, if you use FLAG_SECURE, the Notification will be “Can’t take screenshot…….”.

1. Main Activity code

package com.stackandroid.disablescreenshot;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
public class MainActivity extends Activity {
	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
        		WindowManager.LayoutParams.FLAG_SECURE);
		setContentView(R.layout.activity_main);
	}
}

2. Demonstration

Device shortcut for taking screenshot will not work.

Screen capture using device shortcut is disabled
Screen capture using device shortcut is disabled

You cannot capture screen using DDMS console.

DDMS Screen capture disabled
DDMS Screen capture disabled

Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">