3

I need take screenshot of entire screen in Android, I've searched a lot but they all talked about taking screenshot of specified view, how can I take screenshot of entire screen?

I mean, by program.(Not by DDMS)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Suge
  • 2,808
  • 3
  • 48
  • 79
  • 2
    that depends on which phone you are using. In few phones you can hold the volume down button and power button together to take the screenshot which will be stored in your screenshots folder inside mobile. I would rather suggest to connect your device to the system via USB. and through Eclipse-->DDMS you can take a screenshot of the current screen on your mobile. – khubaib Oct 03 '13 at 07:38
  • i have edited my answer and see the link for programatically take a screenshot on Android – Vamshi Oct 03 '13 at 08:02

6 Answers6

1

There is a library available for taking snapshot through the device its called ASL(Android Screenshot library).

Have a look here with complete source code

Jitender Dev
  • 6,907
  • 2
  • 24
  • 35
1

In eclipse go to DDMS perspective and select your device. Then click on screen capture(camera picture) button.

Go through this link it may be helpful for you...

Community
  • 1
  • 1
Vamshi
  • 1,495
  • 1
  • 15
  • 31
0

Try below code:

// image naming and path  to include sd card  appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   

// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

OutputStream fout = null;
imageFile = new File(mPath);

try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Refer to this answer.

Community
  • 1
  • 1
  • @Matt_9.0.. what is mCurrentUrlMask ?? – Noman Mar 14 '14 at 08:02
  • @Noman I posted the [link](http://stackoverflow.com/a/5651242/2003486) from where I actually referred the answer. There is a discussion in comment about the same and at the end.. `Insted of View v1 = mCurrentUrlMask.getRootView(); I have used View v1 = getWindow().getDecorView().getRootView(); and it works for me.` was the comment by one of the users. So I think that might work. –  Mar 18 '14 at 04:15
  • This approach seems to only capture the activity layout, not things like the status bar contents or any overlays such as alerts. – David Berry Jan 23 '20 at 22:12
0

You need to root your device otherwise it won't work. Also u have to make ur application get SuperUser access. Just implement this code and you will be good to go:

public void screenShot() throws InterruptedException
{
    Process sh;
    try
    {
        sh = Runtime.getRuntime().exec("su", null, null);
        OutputStream os = sh.getOutputStream();
        os.write(("/system/bin/screencap -p " + "/sdcard/Image.png").getBytes("ASCII"));
        os.flush();
        os.close();
        sh.waitFor();
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
Noman
  • 4,049
  • 10
  • 38
  • 59
0

This code return screenshot of visible and unvisible part of layout.

private Bitmap getScreenBitmap() {
    View v = getWindow().getDecorView().findViewById(android.R.id.content);
    v.setDrawingCacheEnabled(true);
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    v.measure(measureSpec, measureSpec);
    width = v.getMeasuredWidth();
    height = v.getMeasuredHeight();

    v.layout(0, 0, width, height);
    v.buildDrawingCache(true);

    //Bitmap b = Bitmap.createBitmap(v.getDrawingCache());

    Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    v.draw(canvas);
    v.setDrawingCacheEnabled(false);
    return b;
}
Kanan
  • 203
  • 1
  • 15
-5

In Eclipse go to Window -> Show View -> Other -> Devices

Select your device and then simply click on "camera picture":

enter image description here

Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106