虽然是个很鸡肋的工具类,但是等5.0以下的设备越来越少的时候就有用了,用到的是MediaProjection,做了封装,使用更简单
调用方法:
初始化:
private ShotUtils shotUtils;
shotUtils = new ShotUtils(getApplicationContext());
shotUtils.init(MainActivity.this);
回调:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case ShotUtils.REQUEST_MEDIA_PROJECTION:
shotUtils.setData(data);
break;
}
}
调用截图的方法:
shotUtils.startScreenShot(new ShotUtils.ShotListener() {
@Override
public void OnSuccess(final Bitmap bitmap) {
iv.setImageBitmap(bitmap);
}
});
截取桌面的效果图
老规矩,放Demo,Demo里是个摇动手机截屏的,工具类也在里面,好用的话给个Start
Demo:https://github.com/bertsir/ScreenShot