0

I am working on a project where I wanted to take screenshots of the current window (inside the application only).

My application consist of a webview, and I am loading webpages on that. webpage contains videos, images... If the webpage plays the video and I try to take the screenshot it shows as black color in the video player position.

Method to take screenshot (Source)

public Bitmap takeScreenshot() {
   View rootView = findViewById(android.R.id.content).getRootView();
   rootView.setDrawingCacheEnabled(true);
   return rootView.getDrawingCache();
}

 public void saveBitmap(Bitmap bitmap) {
    File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}

Used libraries

None of the above are worked. Here is a sample screenshot taken by the deviceenter image description here

Please let me know if there is any way to fix this issue.

droidev
  • 7,352
  • 11
  • 62
  • 94
  • Possibly related/useful: [view.getDrawingCache() is deprecated in Android API 28](https://stackoverflow.com/q/52642055/295004) – Morrison Chang May 15 '19 at 05:56
  • @MorrisonChang I have tried in older APIs and same issue happens – droidev May 15 '19 at 06:00
  • hope this answer helps https://stackoverflow.com/questions/32513379/how-to-record-screen-and-take-screenshots-using-android-api. – Nidhin May 17 '19 at 04:33

0 Answers0