在 android 中停止录制屏幕的预装屏幕录制应用

Stop pre-installed screen recording apps from recording screen in android

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

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

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

据我所知,没有官方的方法可以普遍阻止屏幕 grabs/recordings。

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

上捕获

Window flag: treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.

但是具有更高权限的应用程序可以创建 secure 虚拟显示并使用屏幕镜像来录制您的屏幕,这不符合 secure[=32] =]旗帜。

阅读 this article 了解更多信息:

That would mean that an Android device casting to a DRM-protected display like a TV would always display sensitive screens, since the concept of secure really means “copyrighted”. For apps, Google forestalled this issue by preventing apps not signed by the system key from creating virtual “secure” displays

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

  • 检查是否有任何 external/virtual 显示连接,并 hide/show 您的内容基于此。参见 this
  • 不要在获得 root 权限的设备上显示您的内容

将此代码添加到我的 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;
        }
}

导入需要的东西。