4

I have made a mobile app using react-native (only android for now and it is not an expo app) and I would like to forbid users to take screenshots while the app is open. I know it is impossible to disable this completely but I would like to make it at least more difficult to take screenshots. There are some examples I found but I don't how to implement them for example:

How to prevent Screen Capture in Android

I tried to put:

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

in my app_name/android/app/src/main/java/com/app_name/MainApplication.java file, in the onCreate() method and then I can't compile the app to see if it works. The same is when I tried to create a class like in this:

How do I prevent Android taking a screenshot when my app goes to the background?

There are some npm-s for this issue but I had also no success in installing/using them.

Does anyone know how to set a flag so the users of my react-native (android) app can't take screenshots while using the app?

The error I get when add: getWindow().setFlags and then press Build in android-studio is:

error: package WindowManager does not exist

and I also tried to this package:

yarn add react-native-anti-screenshot
yarn add v1.7.0
[1/4] Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/react-native-anti-screenshot: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/home/mislav/workspace2/umye/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Looks like there is no easy solution to disable screenshots or did i miss something?

I'm pretty new in developing mobile apps so please if you can help me explain it as simple as you can.

Thank you!

Laura
  • 5,088
  • 3
  • 26
  • 37
Mislavoo7
  • 457
  • 1
  • 5
  • 13
  • Set it in `MainActivity.java` instead of `MainApplication.java` – Ravi Jul 17 '18 at 13:06
  • 1
    Please elaborate these sentences more `I can't compile the app`.. Why you can't compile? What is the error? `I had also no success in installing/using them`... What exact issue did you face? – Vikasdeep Singh Jul 17 '18 at 13:06

1 Answers1

-1

try this code in MainActivity.java file:

  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
    if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) 
    {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, 
        WindowManager.LayoutParams.FLAG_SECURE);
    };

 }
Arya Aghaei
  • 495
  • 9
  • 20