从android中的录制屏幕停止预安装的屏幕录制应用程序 [英] Stop pre-installed screen recording apps from recording screen in android

查看:82
本文介绍了从android中的录制屏幕停止预安装的屏幕录制应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flutter,并已禁止正常的应用程序记录屏幕.这是代码

I am using flutter and have disabled normal apps from recording the screen. Here is the code

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

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

The problem is there are some phones where screen recordings apps are pre-installed and above code can't stop them from recording the screen. So is there any other way to stop these apps from recording the screen? On other answers I saw that this was not possible but there are some apps on playstore which successfully achieve this. So there must be a way. I was thinking, as screen recording apps are drawn over , they might be detected through a piece of code hence we can show a pop up while screen recording app is drawn over. Is it possible ? If yes how can we detect if the app is drawn over our app. Thanks.

推荐答案

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

Adding this code to my MainActivity.java solved the problem:

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;
        }
}

导入必需的东西.

这篇关于从android中的录制屏幕停止预安装的屏幕录制应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆