softare development

Disable Screenshot And Recording in Android Studio And React Native

To disable screenshot and recording in android development, we first create a method following in our MainActivity.java file.

This method will also work for the Android version of your React Native Project. Navigate to the android folder and get the MainActivity.java file from the app folder

We will call this method setUpActivityListener(). Next, we’ll add the following code

 private void setupActivityListener() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);            }
            @Override
            public void onActivityStarted(Activity activity) {
            }
            @Override
            public void onActivityResumed(Activity activity) {

            }
            @Override
            public void onActivityPaused(Activity activity) {

            }
            @Override
            public void onActivityStopped(Activity activity) {
            }
            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
            }
            @Override
            public void onActivityDestroyed(Activity activity) {
            }
        });
    }

Next and finally, we will call this method in our onCreate() in the MainActivity.java file as follows

@Override
  public void onCreate() {
    super.onCreate();
    setupActivityListener();
   ...
  }

You’re all set!

Accept Unlimited Number of Arguments in a Javascript Function

Recent Posts

Trump Extends U.S. TikTok Sale Deadline to September 2025

In a surprising turn of events, former President Donald Trump announced on June 19, 2025,…

3 days ago

Master React Native Flexbox

Flexbox is a powerful layout system in React Native that allows developers to create responsive…

6 days ago

Getting Started With TensorFlow

"The journey of a thousand miles begins with a single step." — Lao Tzu Welcome…

1 week ago

Your Mind is a Supercomputer

We often describe ourselves as "processing" information, "rebooting" after a bad day, or feeling "overloaded"…

2 weeks ago

What is a QR Code And How to Create One

QR codes have evolved from a niche tracking technology to an indispensable digital connector, seamlessly…

3 weeks ago

Will AI Replace Software Developers?

Artificial Intelligence (AI) has made remarkable progress in recent years, transforming industries such as healthcare,…

4 weeks ago