Sometimes, we don’t want to allow users to take screenshots or screen recordings of our android application. This is helpful for security issues today so many Android applications prevent Screenshots. In this article, we are going to explain how to prevent Android from taking a screenshot or screen recording.

Prevent taking Screenshot in Android App:

In the MainActivity.java file just you need to add the following code and it will prevent taking Screenshot in Android App.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE);

Complete code for the MainActivity.java file:

import androidx.appcompat.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);

// this will prevent taking screenshot in your app
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

}
}