想做一个在后台运行获取屏幕信息的APP运行在智能电视上,目前已经可以做到,通过使用Android5.0之后加入的录屏功能进行截图.
mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), RECORD_REQUEST_CODE);
mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, intentData);
virtualDisplay = mediaProjection.createVirtualDisplay(
"screen-mirror",
width,
height,
Resources.getSystem().getDisplayMetrics().densityDpi,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mImageReader.getSurface(),
null,
null
);
Image image = mImageReader.acquireLatestImage();
通过这种方法拿到屏幕快照;在智能电视主界面截图都没问题,但是打开各种播放器活着图片查看器,截图出来都是黑色,纯黑色,甚至都能截下来Toast,还有右上角关闭广告的控件,然而就是无法捕捉到视频的信息。
adb shell /system/bin/screencap -p /sdcard/screenshot.png
adb shell screenrecord --size 1280x720 --bit-rate 6000000 --time-limit 30 /sdcard/demo.mp4
还尝试过通过ADB shell screenrecord 命令,无论是截图还是录屏,结果都是除了视频之外所有东西都可以捕获下来,而视频本身始终是黑色的。
头一次在csdn上求助,不知道我将问题描述清楚了没有,希望大佬能够指点迷津!