Вот мой код.
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) throws IOException {
File imagePath = new File(Environment.getExternalStorageDirectory() + "/Protractor"+count+".png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("Mirza", e.getMessage(), e);
} catch (IOException e) {
Log.e("Mirza", e.getMessage(), e);
}
}