Q:

How to take a screen shot with status bar contents in android application?

I have a requirement that I have to take a screenshot of the current window in android. 
This is the code am using, 
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
View screenView = rootView.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);

by using this I could get the application screen shot, but the status bar contents are missing (bluetooth icon, battery status etc).
How can I take a screenshot of the current Android phone window programmatically (including status bar contents)? 
Is it possible? 

A:

On Android 5.0+, use the media projection APIs to take a screenshot of the device screen. See this sample app, as the process is somewhat involved.
On older Android devices, there is no support for programmatic screenshots of the device screen.

