How to take a screenshot of the current MapView?

I have two buttons and a mapView. I want to save the MapView's view when I press one of the buttons.

Anyone got any idea about how I can do this?


You have to add a listener to the button (you should know how this done) and in that listener, do something like that:

boolean enabled = mMapView.isDrawingCacheEnabled();
mMapView.setDrawingCacheEnabled(true);
Bitmap bm = mMapView.getDrawingCache();

/* now you've got the bitmap - go save it */

File path = Environment.getExternalStorageDirectory();
path = new File(path, "Pictures");
path.mkdirs();  // make sure the Pictures folder exists.
File file = new File(path, "filename.png");
BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(file));
boolean success = bm.compress(CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();

mMapView.setDrawingCacheEnabled(enabled);   // reset to original value

In order to have the image show up in the Gallery immediately, you have to notify the MediaScanner about the new image like so:

if (success) {
    MediaScannerClientProxy client = new MediaScannerClientProxy(file.getAbsolutePath(), "image/png");
    MediaScannerConnection msc = new MediaScannerConnection(this, client);
    client.mConnection = msc;
    msc.connect();
}

google map have a function to take a snapshot so use this here is example, it return a bitmap that you can set on a image view its simple..

Bitmap bitmapMapsattelite ;

map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
                        @Override
                        public void onMapLoaded() {
                            // Make a snapshot when map's done loading
                            map.snapshot(new GoogleMap.SnapshotReadyCallback() {
                                @Override
                                public void onSnapshotReady(Bitmap bitmap) {
                                    bitmapMapsattelite = null;
                                    /// make the bitmap null so everytime it //will fetch the new bitmap 
                                    bitmapMapsattelite = bitmap;

                                }

                            });
                        }
                    });