I would like to implement some sort of remote assistance tool (like vnc) for Android. Is there the possibility to capture a screen programmatically on the device?
6 Answers
Something like that might work for you:
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();

- 13,532
- 8
- 45
- 55
-
2Thanks, this is just what I needed! I had a similar problem but I only wanted a Bitmap of my app, not the OS UI etc – Waleed Amjad Aug 08 '11 at 16:31
There is a long discussion of this on android-developers, but the short answer is: You can't programatically take a screenshot of an android device's screen at the moment, unless
- You have root access on that phone, or
- Your application is a system application
The Android Manifest permission READ_FRAME_BUFFER exists (see the api docs here), but can presently only be used by system applications. There are various reasons for this, one being that it is a security risk. If an background can take a screenshot of the phone's screen at any time, then people could use OCR techniques to sniff user's passwords as they were typed in, among other private information.
So no, a VNC application is not possible at the moment without root. To take a screenshot from your computer (while the phone is plugged in via usb) you can use DDMS.

- 6,051
- 5
- 47
- 69
-
Based on what you said here, it sounds like that a system application could be installed via non-stock recovery and not necessarily need to the ROM itself be rooted. I haven't heard of any VNC system applications, even 1.75 years after you posted this answer. There are a lot of custom ROM users out there and it seems that there is quite a void there waiting for someone to come along with a good VNC app. – Emmaly May 21 '12 at 06:33
-
2Regarding point 2: you have to be more than just a system application (i.e. in the system folder), you have to be signed by OS key, which is much more restrictive. This is the difference between a permission being "signatureOrSystem" and "signature". – Rupert Rawnsley Jun 01 '12 at 12:19
You can try the following library: http://code.google.com/p/android-screenshot-library/ Android Screenshot Library (ASL) enables to programmatically capture screenshots from Android devices without requirement of having root access privileges. Instead, ASL utilizes a native service running in the background, started via the Android Debug Bridge (ADB) once per device boot.

- 878
- 7
- 10
-
Your answer is very useful to me but when i use this library it keep showing me a toast saying "Native service not found". Have you encountered such a problem if so please do help me. Thanks – Ravi K. Sharma Apr 23 '13 at 08:15
-
1Nope. After executing: 'screenrecord --verbose --time-limit 5 /sdcard/recvid.mp4' on the getRuntime().exec() method... The process does run, however I get the error: "Permission Denial: broadcast asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACt_ACROSS_USERS_FULL.." However I've been able to run 'screenrecord --help' just fine! – giannileuani Oct 17 '14 at 02:28
put it in onClick ..
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
and write funtcion..
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}

- 60,022
- 51
- 208
- 332

- 33,936
- 20
- 234
- 300
The VNC-type remote tol does exist for "SOME" android devices (mainly Samsung):
TeamViewer QuickSupport
https://play.google.com/store/apps/details?id=com.teamviewer.quicksupport.market
Dos anyone knows how that tool gets screen capturing, and why it supports only limited set of devices?

- 10,605
- 8
- 32
- 42