如何在React-Native应用中防止用户截屏?一些评论中说这行代码可以防止截屏,但我应该在哪里插入它呢?
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
如果有其他方式,请告诉我。
注:我只对 Android 平台感兴趣。
如何在React-Native应用中防止用户截屏?一些评论中说这行代码可以防止截屏,但我应该在哪里插入它呢?
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
如果有其他方式,请告诉我。
注:我只对 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);
}
}
getWindow
方法可以在MainActivity
中调用,但无法在ReactApplication
中使用。 - Junius L