I tried below code but as I run it gives a black screen image on android mobile and on emulator it gives a file, by opening this file I get message as preview not available.
View v = activity.getWindow().getDecorView();
v.setDrawingCacheEnabled(true);
v.destroyDrawingCache();
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, width, height);
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); // clear drawing cache
FileOutputStream fos = null;
File fTree = new File(sdCardRoot,"/fi.png");
fTree.createNewFile();
try {
fos = new FileOutputStream(fTree,true);
if (null != fos) {
b.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.flush();
fos.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Please somebody help. Thank you.
Okay then. You might have to override the below method. The problem is because your view is not created yet and even before that you are trying to get the background which is actually not existing and hence you dont get any image.
Try this,
This method gets called, once your view is drawn and hence you will get the required output by overriding this method.