简体   繁体   English

在root设备上的Android屏幕截图

[英]Android screen capture on rooted device

Screen capture on rooted device I want to capture screen of an android device rooted using APK. 在root设备上的屏幕截图我想捕获使用APK生成的Android设备的屏幕。 I tried 我试过了

process = Runtime.getRuntime().exec("/system/bin/screencap -p " + path + ”/file.png ”);

This command is working fine but it is too slow. 这个命令工作正常但速度太慢。 Then I tried using second option 然后我尝试使用第二个选项

View content = findViewById(android.R.id.content).getRootView();
content.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache());
OutputStream fout = null;
File imageFile = new File(_path,"ScreenImage.png");
try {
    fout = new FileOutputStream(imageFile);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
    fout.flush();
    fout.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

But in this I am getting view of my application not current screen. 但在这里,我正在查看我的应用程序而非当前屏幕。 I am is to capture screen shots an make video out of them I am using FB0 to make video but make problem is to capture screen with speed of 8 frames per second 我是捕捉屏幕截图一个制作视频从他们我使用FB0制作视频,但问题是捕获屏幕速度为每秒8帧

Please suggest solution for speeding this process. 请建议加速此过程的解决方案。 resolution is not problem it can be of poor quality. 分辨率不是问题,可能是质量差。

Since your device is rooted, take a look at framework hide api SurfaceControl's screenshot method. 由于您的设备已植根,请查看framework hide api SurfaceControl的截屏方法。 Didn't test if it's fast enough. 没有测试它是否足够快。

public static Bitmap screenshot(int width, int height) {
    // TODO: should take the display as a parameter
    IBinder displayToken = SurfaceControl.getBuiltInDisplay(
            SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN);
    return nativeScreenshot(displayToken, width, height, 0, 0, true);
}

The normal step to take screenshot is, intercepting screenshot combination key in PhoneWindowManager, then connect to a screenshot service in systemui, this service will call method SurfaceControl.screenshot to take the screenshot. 截取屏幕截图的正常步骤是拦截PhoneWindowManager中的屏幕截图组合键,然后连接到systemui中的截屏服务,此服务将调用方法SurfaceControl.screenshot来截取屏幕截图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM