How can I take screenshot of whole activity on Android, even if content is not visible? Ex. take screenshot of full chat and then generate image file?
I want screenshot invisible area too.
Thanks
One way is to extract the bitmap of the current screen and save it. Try this:
public void takeScreenshot(){
Bitmap bitmap = getScreenBitmap(); // Get the bitmap
saveTheBitmap(bitmap); // Save it to the external storage device.
}
public Bitmap getScreenBitmap() {
View v= findViewById(android.R.id.content).getRootView();
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); // clear drawing cache
return b;
}
Android take screen shot programmatically
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