17

it is easy to this code

Bitmap bitmap;
View v1 = MyView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

and it works great , but this is the case if there is activity.

How can I take a screenshot from service ?

my goal to take a screenshot ones in a hour ,e.i to to take screen shut every hour for example in 12 then in 1 then in 2 .... and so on

Lukap
  • 31,523
  • 64
  • 157
  • 244

2 Answers2

7

To capture ScreenShot for your activity you have to need a View of your activity, and which one is not present in your service so you have to make a TimerTask which will call your activity at every hour and your activity responding it to with current appear view and you can capture the ScreenShot from that. (I think this one is only solution for your problem.)

Or If you want to take a ScreenShot of your current device screen (any application) then you have to root permission, and read framebuffer for that which will give raw data of current screen then convert it to bitmap or any picture file you can do it in your service.

user370305
  • 108,599
  • 23
  • 164
  • 151
  • hi @user370305, can you please give me some example code for reading framebuffer... i need a urgent requirment... – kalandar Mar 02 '13 at 08:00
  • 1
    @kalandar - Look at http://www.pocketmagic.net/2010/11/android-native-screen-capture-application-using-the-framebuffer/#.UTG82TfDs1o – user370305 Mar 02 '13 at 08:44
3

Android Screenshot Library (ASL) provides means for taking snapshots of phone's screen without the need for signing your application or having privileged (root) access to the Android system Click here for ASL

sandy
  • 3,311
  • 4
  • 36
  • 47