11

I want to take a fullscreen screenshot programmatically , for example, one of the android home screen or a menu. How can I get a view of the home screen in my application? I want to take it programmatically!!! It doesn't matter if it requires root mode!

Help me please and sorry for my English!

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nolesh
  • 6,848
  • 12
  • 75
  • 112
  • Oh snap! Just realized (after posting my answer of course -_-): Do you mean from an android application? –  Sep 22 '11 at 12:04
  • 8
    I want to take it programmaticaly!!! – Nolesh Sep 22 '11 at 12:05
  • 1
    What about this question http://stackoverflow.com/questions/2661536/screenshot-android – Tima Sep 22 '11 at 12:18
  • > Did you try > [this](http://www.androidcentral.com/taking-screenshots-without-root) > ? Or in french you can [read > that](http://www.actualitemobile.com/forum/index.php?topic=9490.0) EDIT : So if you want to programm that, you may following these links : - a [command line solution](http://android.amberfog.com/?p=168) (usable in Java) - you may get somes informations [here](http://www.netmite.com/android/mydroid/development/tools/screenshot/src/com/android/screenshot/Screenshot.java) – Dsandre Sep 22 '11 at 12:01
  • Yes, I did! But I want to take it programmatically!!! – Nolesh Sep 22 '11 at 12:06
  • Ok, you may say that on your question – Dsandre Sep 22 '11 at 12:08

3 Answers3

13

Use following code

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

Here MyView is the View through which we need include in screen.

Nirav Dangi
  • 3,607
  • 4
  • 49
  • 60
  • 6
    This just take screenshot of active application only. Not entire android screen. – Nguyen Minh Binh Sep 19 '12 at 08:53
  • @NguyenMinhBinh .. please take a look..http://stackoverflow.com/questions/3067586/how-to-capture-the-android-device-screen-content/8504958#8504958 ..... this may help you... – Nirav Dangi Jun 14 '13 at 10:07
5

Follow the link https://code.google.com/p/android-screenshot-library/downloads/list it allows you entire screenshot of any screen not only your app

adb shell /system/bin/screencap -p /sdcard/img.png this is a shell command take screenshot simple and fast

Try this

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();
Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64
0

In the adb shell you can use command as

adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png

I found this code on this guide on How to take a screenshot on Android.You can refer it for more details.Hope this helps.

Gowtham V
  • 1
  • 1