4

I want to capture a screen shot of Android applications that are running on my phone.

I tried using the ScreenShot UX application. This can be done on an unrooted phone also. Any idea of how to get the screen shot of the application in Android from a service that runs in the background?

I want my Service to capture screen periodically and send to a server.

jonsca
  • 10,218
  • 26
  • 54
  • 62
Abi
  • 4,718
  • 4
  • 20
  • 29
  • 1
    by pressing lock/power button & home/back button at a same time – rajpara Jun 30 '12 at 04:44
  • I want the code for doing it. – Abi Jun 30 '12 at 04:47
  • You should mention that in your question, it sounded like you were off-topic (though you're not) – John Carter Jun 30 '12 at 04:48
  • possible duplicate of [Screenshot Android](http://stackoverflow.com/questions/2661536/screenshot-android) – John Carter Jun 30 '12 at 04:49
  • 1
    That post tells how to create snapshot of a view from the application itself. I want to take the screen shot from a service, irrespective of application – Abi Jun 30 '12 at 04:52
  • take the whole linear layout in drawing cache and draw view onto canvas and save it to bitmap , but you have to enable the drawingcache(`view.setDrawingCacheEnabled(true)`) of that view. – mayank_droid Jun 30 '12 at 05:21
  • @mak_just4anything this can be done only in the same activity. I want to take the screen shot of another application from my service – Abi Jun 30 '12 at 05:33

3 Answers3

12

The only way to take a screenshot of an app that is not your own is by getting the raw framebuffer. The framebuffer is usually located at /dev/fb0 or /dev/graphics/fb0. On some devices (like an LG Optimus One) this can be accessed without root privileges, but on the majority (like a Nexus S) of them you need to be rooted for this. This is usually not allowed for security reasons, as a malicious app could take screenshots in the background and send them to a remote server, revealing information like email IDs and passwords, and in some cases bank account details.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • Is it legal to take screenshot from a service. I want to use it for mobile tracking and not for any malicious app. – Abi Jun 30 '12 at 12:56
  • 1
    You can use a service to call a method in your app to take a screenshot of your own app, but using it with other apps is not possible without using the framebuffers. While you may have a legitimate use for it, many apps could abuse this, and hence it is by and large not available on non rooted devices. – Raghav Sood Jun 30 '12 at 13:15
  • +1 This is great thanks. I notice on my newer nexus devices 4.4.4+ the buffer is in neither of these locations - and idea where it may have moved to? – Dori Sep 03 '15 at 10:12
9

Have a look at Android-screenshot-library, enables to programmatically capture screenshots from Android devices without requirement of having root access privileges.

COD3BOY
  • 11,964
  • 1
  • 38
  • 56
  • Can i run the program without the Desktop application. In the ScreenshotService.java there is a method retreiveRawScreenshot(). It is connecting to a native application. Is that native application running in a PC. http://code.google.com/p/android-screenshot-library/source/browse/demo/src/pl/polidea/asl/ScreenshotService.java – Abi Jun 30 '12 at 05:06
  • @Abi NO! Read upon this : http://code.google.com/p/android-screenshot-library/wiki/UserGuide – COD3BOY Jun 30 '12 at 05:19
  • The above post is also taking from the application. I want to run a service background which takes the screen shot of applications that is running on the phone and send to a server. – Abi Jun 30 '12 at 05:26
  • @Abi AFAIK If you want to take the screenshot of your current device screen (any application)(I suppose this is what you are looking for) then you need to have root permission. – COD3BOY Jun 30 '12 at 05:43
  • It is possible without root permission.I checked the ScreenShot UX application. It is doing without root permission. https://play.google.com/store/apps/details?id=com.liveov.shotux&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5saXZlb3Yuc2hvdHV4Il0. – Abi Jun 30 '12 at 12:53
  • @Abi Read upon the description of Screenshot UX, it clearly says _May require a rooted phone._ (I agree they say there are some exceptions) – COD3BOY Jul 01 '12 at 02:25
  • 2
    Screenshot UX also works on unrooted phones, but only on selected models. – Abi Jul 02 '12 at 04:54
  • Is this library really only used for testing/debugging purposes? I can't see having this app in production with the pre-requisites needed to capture the screen. – Coova Aug 10 '15 at 16:53
  • @Abi did you get your answer? cuz i have the same problem :/ – mazhar Apr 08 '16 at 05:37
8

As of Android 5.0+, you can use the new functionality in the SDK called media projections to do screen capture without root privileges. There is sample code by Google available here.

skunkwerk
  • 2,920
  • 2
  • 37
  • 55