Skip to content

Instantly share code, notes, and snippets.

@januprasad
Created November 26, 2014 05:24
Show Gist options
  • Save januprasad/61e3e26cc22cc55f0f9b to your computer and use it in GitHub Desktop.
Save januprasad/61e3e26cc22cc55f0f9b to your computer and use it in GitHub Desktop.
takeScreenshot take screenshot of android device
public static Bitmap takeScreenshot(Activity activity) {
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
decorChild.setDrawingCacheEnabled(true);
decorChild.buildDrawingCache();
Bitmap drawingCache = decorChild.getDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(drawingCache);
decorChild.setDrawingCacheEnabled(false);
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment