4
votes

Screen capture on rooted device I want to capture screen of an android device rooted using APK. 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

Please suggest solution for speeding this process. resolution is not problem it can be of poor quality.

2
Is this code inside Activity or Service?Jai Kumar

2 Answers

1
votes

Since your device is rooted, take a look at framework hide api SurfaceControl's screenshot method. 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.