I have seen a lot of code snippets for taking a screenshot but was not able to get something which takes the screenshot of the whole screen and not just a view. It should replicate the way we get screenshot using ddms.
Can someone help?
I have seen a lot of code snippets for taking a screenshot but was not able to get something which takes the screenshot of the whole screen and not just a view. It should replicate the way we get screenshot using ddms.
Can someone help?
There is an Android Screenshot library, which is available here. There wiki pages says library can be used to take screenshot of entire screen without the need of root level access, even from an unsigned application. I have never tried it though. You can use it as a starting point.
sh = Runtime.getRuntime().exec("su", null, null);
System.out.println("capturing");
OutputStream outputstream = sh.getOutputStream();
outputstream.write("/system/bin/screencap -p /sdcard/tos_processing.png".getBytes("ASCII"));
outputstream.flush();
outputstream.close();
sh.waitFor();
System.out.println("captured");
bitmap = BitmapFactory.decodeFile("/sdcard/tos_processing.png");
Try this it worked for me...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view = (ImageView) findViewById(R.id.ImageView01);
Button myBtn = (Button) findViewById(R.id.Button01);
myBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View v1 = view.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
ImageView view2 = (ImageView) findViewById(R.id.ImageView01);
view2.setBackgroundDrawable(bitmapDrawable);
}
});
}