I need to take screenshot programmatically of activity view. I have found a lot of answers how to do it, but there is not answer how to do it with opened dialog
Use the "screen capture" button in the "Devices" window of DDMS with a device/emulator connected. This allows you to take screenshots of whatever is on screen, including when a dialog is open.
EDIT: when I answered this question, it was not clear it needed to be done programmatically and was later edited to clarify.