【问题标题】:Failed to prevent screenshot for unity app无法阻止统一应用程序的屏幕截图
【发布时间】:2019-11-24 20:28:58
【问题描述】:

我想在我的统一应用程序上阻止屏幕截图。

所以,我应用了引用以下网址的代码。 https://developer.android.com/reference/android/view/SurfaceView#setSecure(boolean)

它可以在任何安卓设备和截屏应用程序上进行一般截图,除了谷歌助手。

这里有一些重现问题的步骤。

  1. 为 Android Studio 导出 unity 示例应用。
  2. 在 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);
       }
    }
    
  3. 启动示例应用程序。

我还为我的应用引用了以下网址,以防止通过谷歌助手进行截图。 https://developer.android.com/training/articles/assistant#excluding_views

根据这篇文章,如果安全标志设置为 true,谷歌助手会排除当前视图。

所以我找到了所有 SurfaceView 孩子并将安全标志设置为 true。

正如我所写,它可以在任何 Android 设备和截屏应用程序(谷歌助手除外)上进行一般截图。

我也将 ViewGroup 对象更改为统一对象(mUnityPlayer),但结果相同。

我错过了什么?

【问题讨论】:

    标签: android unity3d screenshot


    【解决方案1】:

    我想阻止在我的 unity 应用上截屏。 看看 https://docs.unity3d.com/ScriptReference/PlayerSettings-protectGraphicsMemory.html

    【讨论】:

    • 谢谢,幻想!该选项需要支持 EGL_PROTECTED_CONTENT_EXT 扩展 (docs) 的设备,它不适用于我的 Pixel2 设备。我想我需要找到另一种方式......;)
    猜你喜欢
    • 2013-09-11
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多