在Android 5.0,API 21 之前想要截图系统屏幕必须Root才能完成,5.0之后开放了接口,下面看我们是怎么实现的。
–
1. 涉及到的相关类
1.
MediaProjectionManager官方原话: Manages the retrieval of certain types of {@link MediaProjection} tokens.
这个类通过Context#getSystemService中MEDIA_PROJECTION_SERVICE获取,他的功能就是获取MediaProjection2.
MediaProjection官方原话:A token granting applications the ability to capture screen contents and/or record system audio. The exact capabilities granted depend on the type of MediaProjection.在这个类中我们能获取到屏幕的内容
3.
ImageReader官方原话:The ImageReader class allows direct application access to image data
rendered into a {@link android.view.Surface}
通过这个类我们可以把Surface

本文介绍了在Android 5.0及以上版本如何不借助Root权限实现屏幕截图。主要涉及MediaProjectionManager、MediaProjection和ImageReader三个类的合作。通过获取用户授权,利用ImageReader将屏幕内容转换为Bitmap并保存。
最低0.47元/天 解锁文章
1858





