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 device
Please let me know if there is any way to fix this issue.