I actually just did this the other day and it was a pain to get a screenshot of the entire Activity, while also making sure to remove the StatusBar from the image (as it will appear as a black rectangle in the drawing cache). This method will also allow you to overlay the returned image with some color (ie. fading)):
public static Bitmap getActivitySnapshot(Activity activity, boolean fade){
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
Bitmap bmap = view.getDrawingCache();
Rect statusBar = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(statusBar);
Bitmap snapshot = Bitmap.createBitmap(bmap, 0, statusBar.top, bmap.getWidth(), bmap.getHeight() - statusBar.top, null, true);
if(fade && snapshot != null){
Canvas canvas = new Canvas(snapshot);
Paint paint = new Paint();
paint.setColor(Color.parseColor("#88121212"));
canvas.drawRect(0, 0, snapshot.getWidth(), snapshot.getHeight(), paint);
}
view.setDrawingCacheEnabled(false);
return snapshot;
}
If you don't want the fading part, the important parts would just be:
public static Bitmap getActivitySnapshot(Activity activity){
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
Bitmap bmap = view.getDrawingCache();
Rect statusBar = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(statusBar);
Bitmap snapshot = Bitmap.createBitmap(bmap, 0, statusBar.top, bmap.getWidth(), bmap.getHeight() - statusBar.top, null, true);
view.setDrawingCacheEnabled(false);
return snapshot;
}
You may also want to catch the OutOfMemoryError that may be thrown when working with large Bitmaps.