【发布时间】:2019-11-24 20:28:58
【问题描述】:
我想在我的统一应用程序上阻止屏幕截图。
所以,我应用了引用以下网址的代码。 https://developer.android.com/reference/android/view/SurfaceView#setSecure(boolean)
它可以在任何安卓设备和截屏应用程序上进行一般截图,除了谷歌助手。
这里有一些重现问题的步骤。
- 为 Android Studio 导出 unity 示例应用。
-
在 onCreate 函数 (UnityPlayerActivity.java) 中应用以下代码。
View v = this.getWindow().getDecorView(); ViewGroup vg = (ViewGroup) v; for( int i=0; i< vg.getChildCount(); i++) { if ( vg.getChildAt(i) instanceof SurfaceView) { ((SurfaceView) vg.getChildAt(i)).setSecure(true); } } - 启动示例应用程序。
我还为我的应用引用了以下网址,以防止通过谷歌助手进行截图。 https://developer.android.com/training/articles/assistant#excluding_views
根据这篇文章,如果安全标志设置为 true,谷歌助手会排除当前视图。
所以我找到了所有 SurfaceView 孩子并将安全标志设置为 true。
正如我所写,它可以在任何 Android 设备和截屏应用程序(谷歌助手除外)上进行一般截图。
我也将 ViewGroup 对象更改为统一对象(mUnityPlayer),但结果相同。
我错过了什么?
【问题讨论】:
标签: android unity3d screenshot