【问题标题】:Stop pre-installed screen recording apps from recording screen in android停止预先安装的屏幕录制应用程序在 android 中录制屏幕
【发布时间】:2020-07-29 15:20:31
【问题描述】:

我正在使用颤振,并已禁用普通应用程序录制屏幕。 这是代码

getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);

问题是有些手机预装了录屏应用,上面的代码无法阻止它们录屏。 那么有没有其他方法可以阻止这些应用程序录制屏幕呢? 在其他答案中,我看到这是不可能的,但 Playstore 上有一些应用程序成功地实现了这一点。所以一定有办法。 我在想,当屏幕录制应用程序被绘制时,它们可能会通过一段代码被检测到,因此我们可以在屏幕录制应用程序被绘制时显示一个弹出窗口。 可能吗 ?如果是,我们如何检测应用程序是否被绘制在我们的应用程序上。 谢谢。

【问题讨论】:

    标签: android flutter screen-recording


    【解决方案1】:

    据我所知,没有官方方法可以普遍防止屏幕抓取/录制。

    这是因为FLAG_SECURE 只是阻止在non-secure displays 上捕获:

    窗口标志:将窗口内容视为安全,防止其出现在屏幕截图中或在非安全显示器上查看。

    但具有提升权限的应用可以创建安全虚拟显示并使用屏幕镜像来记录您的屏幕,这不尊重 secure 标志。

    阅读this article了解更多信息:

    这意味着投射到受 DRM 保护的显示器(如电视)的 Android 设备将始终显示敏感屏幕,因为安全的概念实际上意味着“受版权保护”。对于应用程序,Google 通过阻止未由系统密钥签名的应用程序创建虚拟“安全”显示来预防此问题

    关于某些应用程序仍然可以做到这一点,您可以尝试以下方法:

    • 检查是否连接了任何外部/虚拟显示器,并据此隐藏/显示您的内容。见this
    • 不要在有根设备上显示您的内容

    【讨论】:

    • 嗨,我尝试通过 MethodChannel 检查颤振(android)中的虚拟显示器,但找不到合适的方法。你能指导我正确的代码吗?谢谢
    • 对不起。我对颤振不熟悉。 SO上可能还有其他帖子可以帮助您。
    【解决方案2】:

    将此代码添加到我的 MainActivity.java 解决了问题:

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!this.setSecureSurfaceView()) {
            Log.e("MainActivity", "Could not secure the MainActivity!");
        }
    
    }
    
    
    
    private final boolean setSecureSurfaceView() {
        ViewGroup content = (ViewGroup) this.findViewById(android.R.id.content);
        //Intrinsics.checkExpressionValueIsNotNull(content, "content");
        if (!this.isNonEmptyContainer((View) content)) {
            return false;
        } else {
            View splashView = content.getChildAt(0);
            //Intrinsics.checkExpressionValueIsNotNull(splashView, "splashView");
            if (!this.isNonEmptyContainer(splashView)) {
                return false;
            } else {
                View flutterView = ((ViewGroup) splashView).getChildAt(0);
                //Intrinsics.checkExpressionValueIsNotNull(flutterView,          "flutterView");
                if (!this.isNonEmptyContainer(flutterView)) {
                    return false;
                } else {
                    View surfaceView = ((ViewGroup) flutterView).getChildAt(0);
                    if (!(surfaceView instanceof SurfaceView)) {
                        return false;
                    } else {
                        ((SurfaceView) surfaceView).setSecure(true);
                        this.getWindow().setFlags(8192, 8192);
                        return true;
                    }
                }
            }
        }
    
    }
    
        private final boolean isNonEmptyContainer(View view) {
            if (!(view instanceof ViewGroup)) {
                return false;
            } else {
                return ((ViewGroup) view).getChildCount() >= 1;
            }
    }
    

    导入需要的东西。

    【讨论】:

    • @Parashant Pandey 你能帮我在原生安卓应用中做同样的代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    相关资源
    最近更新 更多