How can I programmatically perform a screen capture on an Android phone?
3 Answers
You cannot do this from an android app except on a rooted phone, as you don't have permission to access the framebuffer device.
You can however do it over adb from the DDMS window of your development machine, as adb runs in the graphics group which has permission to the framebuffer.
If you want to do something similar in native code on a rooted device, look at the sources to the adb daemon.
EDIT: It appears this may be changing and there may be non-root capability in more recent android releases, but I'm not sure of the details.

- 39,853
- 6
- 84
- 117
-
that's patently incorrect. why anyone would upvote this answer is bewildering. – Yevgeny Simkin Mar 03 '11 at 05:41
-
2@Dr.Dedel It is actually quite correct. See the group ownership and permissions on the framebuffer device file, and the fact that no locally activated user code on a secure device is able to run in the necessary group. If you talk to the android architects about this, it was a quite purposeful user-privacy decision to not let applications take screenshots. – Chris Stratton Mar 03 '11 at 15:39
-
but applications can and do take screen shots. They simply don't do it via the screen buffer. So, perhaps this methodology will be disabled at some point in the future (unlikely), but in the mean time, your answer is in fact somewhat misleading as you don't provide the (obvious) caveat that if the intention is to simply take a snap of what's on the screen, there is no need to have a rooted device for this and in most cases it's a grand total of 5 lines of code. – Yevgeny Simkin Mar 03 '11 at 17:21
-
2@Dr.Dedel An application's main view and the screen are not synonymous, though in many cases it may be a suitable substitute. Also, please note that the question (which is relatively ancient and likely abandoned) does not specify that the desire is to capture a view of the capturing application - which is the only case in which your idea will work. – Chris Stratton Mar 03 '11 at 17:45
-
Has there been any update regarding non-root capture capabilities? – kevlar Dec 26 '12 at 23:28
Here's a sample of how to convert a view to a bitmap. Just grab your top view and have at it. This absolutely works and you ABSOLUTELY don't need to have a rooted device for this!
http://www.brighthub.com/mobile/google-android/articles/30676.aspx

- 39,853
- 6
- 84
- 117

- 27,946
- 39
- 137
- 236
-
2This is capturing a view, not the screen itself. For some purposes it may be sufficient and therefore useful. But it is quite well known in the developer community that you cannot capture the actual screen buffer from within an application on a secured device. – Chris Stratton Mar 03 '11 at 15:41
-
I think for the purpose of this question, it is sufficient to offer him advice on how to grab the parent view (which for all intents and purposes is the screen buffer). So, you're technically right, but I think he's simply not wording his question perfectly. What (I think) he wants is simply to take a bitmap screen grab of whatever happens to be displayed on his screen, which is both trivial and doesn't require root permissions. – Yevgeny Simkin Mar 03 '11 at 17:17
-
5My suspicion is that he wants to capture the screen of another application. If it was his own app, using the screen capture built into DDMS is fastest - no need to write a single line of code. Your suggestion would be most useful if he needed to ship an application with the built-in capability to capture the essence of its own UI on the user's device. – Chris Stratton Mar 03 '11 at 17:48
try something like this:
View v1=childView.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm=v1.getDrawingCache();
if(bm!=null){
//save the file
}

- 693
- 1
- 6
- 19