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
Try out this library: https://github.com/jraska/Falcon.
It takes screenshots of all active windows of application including dialogs and could figure out your problem.