Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 219
Vishnu Cyruz Avatar asked May 30 '17 11:05

Vishnu Cyruz


1 Answers

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.

like image 62
CommonsWare Avatar answered Nov 14 '22 23:11

CommonsWare