Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Take a screenshot programatically in Android
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
You can’t perform that action at this time.