I am working on a android app which takes screenshot of the fragment containing google map. When user clicks on share button it takes the screenshot of the fragment view and allows user to share it via email. Following is my fragment view.
When I try to take a screenshot of the map I get following result
Following is my code to take a screenshot:
public static File takeScreenShot(View view) {
String path = Environment.getExternalStorageDirectory().toString() + "/" + System.currentTimeMillis()+ ".jpg";
view.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
OutputStream out = null;
File imageFile = new File(path);
try {
out = new FileOutputStream(imageFile);
// choose JPEG format
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
} catch (FileNotFoundException e) {
// manage exception
} catch (IOException e) {
// manage exception
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception exc) {
}
}
return imageFile;
}
Following is the code to share the map view
Intent intentShare = new Intent(Intent.ACTION_SEND);
intentShare.setType("image/*");
intentShare.putExtra(Intent.EXTRA_STREAM, Uri.parse(ScreenShotTaker.takeScreenShot(view).toURI().toString()));
startActivity(intentShare);