Android实现录屏和截屏功能

本文介绍了如何在Android中使用MediaProjectionManager实现屏幕录制和截图功能。MediaProjectionManager的createScreenCaptureIntent()用于启动授权请求,成功后通过getMediaProjection()获取MediaProjection实例。ImageReader用于接收Surface的图像数据,通过ImageReader.newInstance()创建并利用acquireLatestImage()获取屏幕图像,实现截图操作。录屏原理相同,不过是连续获取多帧图像。
摘要由CSDN通过智能技术生成

1. MediaProjectionManager介绍

用于获取screen capture的主要类,在Android 5.0(Api Level 21)时添加。
核心方法:
(1)创建:public Intent createScreenCaptureIntent ()

Returns an Intent that must be passed to startActivityForResult() in order to start screen capture. The activity will prompt the userwhether to allow screen capture. The result of this activity should be passed to getMediaProjection.

(使用时会弹出授权弹窗,只有用户授权后才能使用)

(2)获取:public MediaProjection getMediaProjection (int resultCode,
Intent resultData)

Retrieve the MediaProjection obtained from a succesful screen capture request. Will be null if the result from the startActivityForResult() is anything other than RESULT_OK.

2.所需权限

<uses-permission and
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值