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)

2
  • 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 3, 2013 at 7:38
  • i have edited my answer and see the link for programatically take a screenshot on Android
    – Vamshi
    Oct 3, 2013 at 8:02

6 Answers 6

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

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...

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.

3
  • @Matt_9.0.. what is mCurrentUrlMask ??
    – Noman
    Mar 14, 2014 at 8:02
  • @Noman I posted the link 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.
    – user3513843
    Mar 18, 2014 at 4:15
  • This approach seems to only capture the activity layout, not things like the status bar contents or any overlays such as alerts. Jan 23, 2020 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();
    }

}
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;
}
-5

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

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

enter image description here

1
  • 1
    Read the question asked.. !!
    – Noman
    Mar 14, 2014 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.