如何防止用户在 React-Native 应用程序中截取屏幕截图? 我在一些关于其他已发布问题的评论中读到,人们说这行代码会阻止屏幕截图,但我到底应该在哪里插入它?
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
或者,如果有任何其他方式,请告诉我。
P.S:我有兴趣只了解 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);
}
}
关于android - 如何防止 Android 或 React-Native 应用程序中的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56613667/