Disable Screen Capture/ScreenShot in React Native App

扶醉桌前 提交于 2019-12-30 10:10:09

问题


I have came across few solutions specific for ios and Android to prevent screen-capturing and taking screenshots. But how do i disable screen-capturing in react native?


回答1:


In android

/android/app/src/main/java/com/{Project_Name}/MainActivity.java

write some Import Statements

import android.os.Bundle;
import android.view.WindowManager;

Prevent capture screen by setFlag secure use below code inside the MainActivity class

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }

If you want to remove flag secure

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);

iOS

// Overlay screen by added 2 two into appDelegate.m

   - (void)applicationWillResignActive:(UIApplication *)application {

// fill screen with our own colour
UIView *colourView = [[UIView alloc]initWithFrame:self.window.frame];
colourView.backgroundColor = [UIColor whiteColor];
colourView.tag = 1234;
colourView.alpha = 0;
[self.window addSubview:colourView];
[self.window bringSubviewToFront:colourView];

// fade in the view
[UIView animateWithDuration:0.5 animations:^{
  colourView.alpha = 1;
}];
}

- (void)applicationDidBecomeActive:(UIApplication \*)application {
// grab a reference to our coloured view
UIView \*colourView = [self.window viewWithTag:1234];
// fade away colour view from main view
[UIView animateWithDuration:0.5 animations:^{
colourView.alpha = 0;
} completion:^(BOOL finished) {
// remove when finished fading
[colourView removeFromSuperview];
}];
}



回答2:


Prevent Capture Screen

Android

Prevent capture screen by setFlag secure

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

If you want to remove flag secure

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);



回答3:


In android

/android/app/src/main/java/com/{Project_Name}/MainActivity.java

write some Import Statements

import android.os.Bundle;
import android.view.WindowManager;

Prevent capture screen by setFlag secure use below code inside the MainActivity class

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }


来源:https://stackoverflow.com/questions/54998051/disable-screen-capture-screenshot-in-react-native-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!