问题
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