0

I'm doing some research for a client for auditing app and would like to know whether there is a way, without rooting the device, to take snapshots from a service in the background?

It should be able to take a snapshot of any activity in the foreground. Is there any programatic way of doing this?

Bended
  • 494
  • 1
  • 7
  • 22

1 Answers1

0

Something like below should work:

View rootView = MainActivity.this.getWindow().getDecorView().getRootView();
rootView.setDrawingCacheEnabled(true);      
rootView.measure(MeasureSpec.makeMeasureSpec(this.screenWidth/*specify the width here*/, MeasureSpec.EXACTLY), 
MeasureSpec.makeMeasureSpec(this.screenHeight/*specify the height here*/, MeasureSpec.EXACTLY));
rootView.layout(0, 0, rootView.getMeasuredWidth(), rootView.getMeasuredHeight()); 
rootView.buildDrawingCache(false);
Bitmap bmScreen = Bitmap.createBitmap(rootView.getDrawingCache());

This code requires the activity to be in memory and in the foreground. Without root access and without modifying Android's source there is no way you can one can take a screenshot. I too researched a lot on it and this was the best I could come up with. In the end we ended up taking the screenshots on Activity's level. However, just in case you're open to root access, here is the link on how to do it.

Community
  • 1
  • 1
Varun Singh
  • 1,135
  • 13
  • 18
  • Thank you but I need to get it from a background service not from a foreground activity. – Bended Feb 02 '15 at 15:36
  • This code requires the activity to be in memory and in the foreground. Without root access and without modifying Android's source there is no way you can one can take a screenshot. I too researched a lot on it and this was the best I could come up with. In the end we ended up taking the screenshots on Activity's level. However, just in case you're open to root access, [here](http://stackoverflow.com/a/20184485) is the link on how to do it. – Varun Singh Feb 02 '15 at 17:13
  • Thank you for the info. Please write this as an answer and I will choose it – Bended Feb 03 '15 at 07:21