如何在本机应用程序中禁用屏幕截图? [英] How to disabled screenshoots in react-native app?
问题描述
我已经使用react-native制作了一个移动应用程序(目前仅适用于android,它不是expo应用程序),并且我想禁止用户在该应用程序打开时进行屏幕截图.我知道不可能完全禁用此功能,但我想至少要更难截取屏幕截图.我找到了一些示例,但是我不知道如何实现它们,例如:
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:
我试图放:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
在我的app_name/android/app/src/main/java/com/app_name/MainApplication.java
文件中的
在onCreate()
方法中,然后我无法编译该应用程序以查看其是否有效.同样,当我尝试创建这样的类时:
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:
此问题有一些npm-s,但我在安装/使用它们方面也没有成功.
There are some npm-s for this issue but I had also no success in installing/using them.
有人知道如何设置标志,以便我的react-native(android)应用程序的用户在使用该应用程序时无法截屏吗?
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?
添加时出现错误:getWindow().setFlags
,然后在android-studio中按Build
:
The error I get when add: getWindow().setFlags
and then press Build
in android-studio is:
错误:软件包WindowManager不存在
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.
谢谢!
推荐答案
在MainActivity.java文件中尝试以下代码:
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);
};
}
这篇关于如何在本机应用程序中禁用屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!