android - 如何防止 Android 或 React-Native 应用程序中的屏幕截图

标签 android react-native screenshot snapshot

如何防止用户在 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);
    }
}

DEMO

关于android - 如何防止 Android 或 React-Native 应用程序中的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56613667/

相关文章:

android Place Autocomplete 如何默认在顶部获取搜索位置列表

Android拖放问题不显示

reactjs - TextInput 清除时速度慢,屏幕上有很多内容

git - 显示存储在 GitHub 和本地不同分支中的 GitHub README 屏幕截图

android - Switch 的 drawableRight 的奇怪行为

android - 如何解决ANDROID_SDK_ROOT=undefined(推荐设置)和ANDROID_HOME=undefined(DEPRECATED)

react-native - react 原生 : 'React' refers to a umd global but the current file is a module consider adding an import instead

react-native - 如何在 React Native 中实现 'almost' 全屏模式?

linux - 从 linux+bash 中的图像获取行的值

iphone - Xcode 管理器屏幕捕获问题