Android screen capture on root device

Screen capture on the root device I want to capture the screen of an Android device embedded using the APK. I tried

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

This command works fine, but it is too slow. Then I tried to use the 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 get the idea that my application is not the current screen. I have to capture screenshots to make videos of them. I use FB0 to create a video, but the problem is screen capture at 8 frames per second.

Please suggest a solution to expedite this process. resolution is not a problem; it may be of poor quality.

+4
source share
2 answers

Since your device is rooted, take a look at the screenshot of the hide hide api SurfaceControl method. Did not check if he was 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 usual step is to take a screenshot by capturing the combination of the combination of screenshots in PhoneWindowManager, then connect to the screenshot service in systemui, this service will call the SurfaceControl.screenshot method to take a screenshot.

+1
source

Source: https://habr.com/ru/post/1492019/


All Articles