TrinityTuts

Prevent application content from screenshot or screen recording Android

Last updated on March 13th, 2020 at 11:28 am

In this post I’m going to explain to you how you can prevent your app content from recording or from screenshot some time it’s very important that you don’t allow your important content from copy or from recording. Using below code you can prevent your content from a screenshot or from recording.

Step 1. Create a new project in Android Studio and open your activity in which you want to prevent from screen recording.

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}

Complete Activity Code

package com.screenshotpermission;

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);
        if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
        }
    }
}

That’s all you can check below video in which you can see how it’s working

Hope this code help you.