[英]How to prevent screenshots in Android or React-Native app
如何阻止用户在React-Native应用程序中截取屏幕截图? 我已经阅读了一些其他一些帖子的评论,人们说这行代码会阻止截图,但我究竟要在哪里插入?
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
或者,如果有任何其他方式让我知道。
PS:我很有兴趣只知道Android平台。
您需要在MainActivity.java
插入它,在MainActivity.java
覆盖onCreate
方法。
package com.reactnativepreventscreenshot;
import android.os.Bundle;
import android.view.WindowManager;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "reactnativepreventscreenshot";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.