I have looked at probably every SO article concering capturing the screen (screenshot, screendump) programmatically on Android, and they usually all end up with the same answer.
The problem with it is that it captures the View that you have specified, but it does NOT capture any Dialogs that may be "on top of" the "root view". This is the code I use, that fails to capture anything "on top":
Bitmap bitmap;
View v1 = findViewById(android.R.id.content);
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "myDump.jpg");
FileOutputStream outputStream;
try
{
outputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 10, outputStream);
outputStream.flush();
outputStream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
The question is: how can I capture the entire screen, including Dialogs that are on top? I am only interested in capturing the app that I am writing, not the home screen or anything like that, just anything that is on top of my root view.
I did read something about rooting, but I really hope that taking a complete screendump of the app Im writing cannot be impossible.
Press Command-Shift-4. Press the Space bar. Move the pointer over the desired interface element, which turns blue. Option-click to take the screenshot sans drop shadow.
Press the Power and Volume down buttons at the same time. If that doesn't work, press and hold the Power button for a few seconds. Then tap Screenshot.
use this library .... it works great for me. https://github.com/jraska/Falcon
// Saving screenshot to file
Falcon.takeScreenshot(this, imageFile);
// Take bitmap and do whatever you want
Bitmap bitmap = Falcon.takeScreenshotBitmap(this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With