Created
January 20, 2016 07:41
-
-
Save PDDStudio/36383f6fecf815c7ee7a to your computer and use it in GitHub Desktop.
Take a screenshot programatically in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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