Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take screenshot of WHOLE activity page programmatically? [closed]

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?

enter image description here

I want screenshot invisible area too.

Thanks

like image 592
Giorgi Asaturyan Avatar asked Dec 25 '14 20:12

Giorgi Asaturyan


1 Answers

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

like image 129
thepace Avatar answered Oct 12 '22 10:10

thepace