
In this tutorial we will learn how to prevent someone to take screenshot or record screen on your Android Application.
In some cases , we don’t want to allow to take screenshots or screen recordings of our android application. Here we are going to explain how to How To Disable Screenshot and Screen Recording in Android Application.
This feature is very useful where you don’t want anyone to take screenshot or screen recording. For this we will use FLAG_SECURE in our Main Activity with few line of coding and when someone will try to take screenshot is will toast up with some warning message.
lets see how will do it.
Create a new project
- Create a new project in Android Studio File–>New–>New Project.
- Enter Application Name, Package Name, Select Empty Activity and click on finish.
Design your layout
- Design your project according to your need.
Add code to your activity
- Open your MainActivity.java file.
- Copy below code to your activity to Disable Screenshot and Screen Recording in Android Application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.legendblogs.demo; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.WindowManager; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //below code will Disable Screenshot and Screen Recording in Android Application getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); } } |
FLAG_SECURE Indicates that the display has a secure video output and supports compositing secure surfaces. Secure surfaces are used to prevent content rendered into those surfaces by applications from appearing in screenshots or from being viewed on non-secure displays. Protected buffers are used by secure video decoders for a similar purpose.
Output result
When someone will try to take screenshot it will popup with toast message.


Subscribe To Our YouTube Channel
Like Us On Facebook
Other Tutorials-
- Facebook Account Kit SMS Authentication for Android
- Android Cascading Spinners Using Php Mysql
- Android Upload Image To Server Using PHP MySql
- Dashboard Design In Android Studio Using CardView Tutorial
- Android Build Intro Slider Using ViewPager
- Splash Screen Android
- Login Screen Using LinearLayout
- Awesome Login Screen Design Using Constraint Layout
- Firebase phone number authentication in android studio
- Android Working with Recyclerview and Cardview
- How to disable screenshot and screen recording in android application