Take a screenshot - Background Service

For Lollipop and above you can use the MediaProjection API of Google to take the screenshot but you need to ask for the permission from the user.

You can find the sample screen capture code using MediaProjection Here

For the devices less then Lollipop you need root permission for it.


To get a screenshot containing views not belonging to your app you'll need to use the MediaProjectionManager.

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