android - 在 React Native App 中禁用屏幕捕获/ScreenShot
问题描述
我遇到了一些专门针对 ios 和 Android 的解决方案,以防止屏幕捕获和截屏。但是如何在本机反应中禁用屏幕捕获?
解决方案
安卓
里面/android/app/src/main/java/com/{Project_Name}/MainActivity.java
您可以添加以下行。通过 setFlag 防止捕获屏幕FLAG_SECURE
,使用下面的代码作为示例:
import android.os.Bundle;
import android.view.WindowManager;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
稍后当您要删除安全标志时
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
iOS
中的覆盖屏幕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];
}];
}
推荐阅读
- dicom - 如何判断我的 dicom 文件是否被压缩?
- mysql - SQL 或 R:从具有二进制数据类型的列中查找并显示所有 '1' 的索引,并存储在另外 1 列或更多列中
- powershell - 需要为意外结果添加一个步骤
- node.js - 使用子类型进行查询时 Apollo 返回错误
- c# - ASP.NET 应用程序中的“找不到名称映射”错误
- kubernetes - 错误未从 Kubernetes 应用程序触发 Rundeck
- apache-kafka - 分区 0 的偏移量非常接近于与其余分区的偏移量之和
- selenium - 如何使用 Selenium-Python 从日历中选择第二天
- reactjs - HowTo:从 _app.js 中的 express 服务器获取 req.ip?
- reactjs - TypeError:无法读取未定义的属性“地图”(jest.js)