【发布时间】:2026-01-11 11:05:01
【问题描述】:
我正在开发一个系统应用程序,我需要对主屏幕进行截图。
在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