【问题标题】:android SurfaceControl screenshot return nullandroid SurfaceControl屏幕截图返回null
【发布时间】:2017-07-13 17:46:03
【问题描述】:

我正在开发一个系统应用程序,我需要对主屏幕进行截图。

在android 4.0到4.2中,com.android.view.Surface中有一个隐藏的API,通过调用Surface.screenshot(width, height)可以完美运行,它返回截图位图:

    public static Bitmap screenshot(int width, int height);

自 android 4.3 起,screenshot() 方法已移至 com.android.view.SurfaceControl。但是,当我像在 android 4.2 中一样调用 SurfaceControl.screenshot(width, height) 时,它返回 null。

应用程序具有READ_FRAME_BUFFER权限,并使用平台证书签名, 它的 sharedUserId 为“android.uid.system”。它在 4.0 和 4.2 中运行良好,但在 4.4 中返回 null,在 logcat 中没有警告或错误。

在 android 4.0 到 4.2 中,Surface 类没有被隐藏,只是方法 screenshot() 被隐藏了。在 android 4.4 中,SurfaceControl 类是隐藏的。

那么,我怎样才能让它在 android 4.4 中工作?

【问题讨论】:

    标签: android screenshot


    【解决方案1】:

    这似乎是模拟器的问题。 4.2模拟器可以截图,4.4模拟器不能。 但它在 4.2 和 4.4 的真实手机上都可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-13
      • 2021-07-12
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 1970-01-01
      相关资源
      最近更新 更多