0

I want to make an app that takes screenshots of the device every 10 seconds, even when app is running in the background.

I don't know how to do this.

Is there any way to do this with a device that's not rooted?

ChuongPham
  • 4,761
  • 8
  • 43
  • 53

3 Answers3

0

In order to capture ScreenShot of your activity you need a View from your activity, and which isn't present in your service so you have to make a TimerTask which will call your activity at every moment to get the current view of the activity and you can capture the ScreenShot from that.

otherwise If you want to take a ScreenShot of your current device screen or any other app 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.

try {
 Process sh = Runtime.getRuntime().exec("su", null,null);    
                    OutputStream  os = sh.getOutputStream();
                    os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
                    os.flush();          
                    os.close();
                    sh.waitFor();
} catch (IOException e) {
                     e.printStackTrace();
                         }
Nadir Belhaj
  • 11,953
  • 2
  • 22
  • 21
0

Here is how to capture the screen shot on Android.

Also an example of Handler and Timer

And a very similar post that asks for the same.

Community
  • 1
  • 1
Jonathan Solorzano
  • 6,812
  • 20
  • 70
  • 131
-1

First take code to take screen shot programatically in android. It is available is stack overflow. Then use handler to call this method in every 10 seconds.

Mohit Rajput
  • 439
  • 3
  • 18