I am working on an Android code where I get screenshot on button click. I could able to get the screenshot of the current activity first time but when I take the screenshot again it is not updating. I found that it takes the screenshot again but it saves with old image. This is my code :
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
v1.refreshDrawableState();
v1.buildDrawingCache(true);
Bitmap myBitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.destroyDrawingCache();
v1.setDrawingCacheEnabled(false);
String filePath = Environment.getExternalStorageDirectory() + File.separator + "Pictures/myapp.png";
File imagePath = new File(filePath);
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
myBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
MediaScannerConnection.scanFile(MainActivity.this,
new String[]{imagePath.toString()}, null,
new MediaScannerConnection.OnScanCompletedListener()
{
public void onScanCompleted(String path, Uri uri)
{
Log.w("ExternalStorage", "Scanned " + path + ":");
Log.w("ExternalStorage", "-> uri=" + uri);
}
});
send(imagePath);
}
catch (FileNotFoundException e)
{
Log.e("MSG", e.getMessage(), e);
}
catch (IOException e)
{
Log.e("MSG", e.getMessage(), e);
}
Though this question is asked in different ways and have answers, I still couldn't solve the bug.