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)
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)
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
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.
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();
}
}
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;
}
In Eclipse go to Window -> Show View -> Other -> Devices
Select your device and then simply click on "camera picture":