我正在使用Flutter,并已禁止正常的应用程序记录屏幕。 这是代码
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
问题是某些手机上预装了屏幕录制应用程序,并且以上代码无法阻止它们录制屏幕。 那么,还有其他方法可以阻止这些应用记录屏幕吗? 在其他答案上,我看到这是不可能的,但是playstore上有一些应用程序可以成功实现这一目标。所以一定有办法。 我在想,当屏幕录制应用程序被绘制时,可能会通过一段代码检测到它们,因此当屏幕录制应用程序被绘制时,我们可以显示一个弹出窗口。 可能吗 ?如果是,我们如何检测该应用程序是否绘制在我们的应用程序上。 谢谢。
答案 0 :(得分:0)
据我所知,目前还没有正式的方法来普遍防止屏幕抓取/录制。
这是因为FLAG_SECURE
仅阻止捕获non-secure displays:
窗口标记:将窗口的内容视为安全的,防止其出现在屏幕截图中或在非安全的显示器上查看。
但是具有较高权限的应用程序可以创建安全虚拟显示并使用屏幕镜像来记录您的屏幕,这不遵守安全标志。
阅读this article了解更多信息:
这意味着投放到受电视保护的受DRM保护的显示器(如电视)的Android设备将始终显示敏感屏幕,因为安全的概念确实意味着“受版权保护”。对于应用程序,Google通过阻止未使用系统密钥签名的应用程序创建虚拟的“安全”显示来预防此问题
关于某些应用仍然可以做到的方式,您可以尝试以下方法:
答案 1 :(得分:0)
将此代码添加到我的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;
}
}
导入必需的东西。