0

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. Actual fragment view showing route on the map

When I try to take a screenshot of the map I get following result after taking screenshot

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);
Akshay
  • 833
  • 2
  • 16
  • 34
  • 1
    AFAIK, the map is shown by a `SurfaceView`, which will not work with your screenshot mechanism. – CommonsWare Sep 09 '15 at 17:18
  • Then Whats the way to take a screenshot. I also found that google map has a snapshot method. But the problem is it takes screenshot of only map not the whole fragment. I have some more data along with the map which I didn't post in the question. – Akshay Sep 09 '15 at 17:22
  • It's Works... http://stackoverflow.com/questions/13773658/capture-screen-shot-of-googlemap-android-api-v2/18093295#18093295 – Arjun Vyas Jan 18 '17 at 12:18
  • Hi @Akshay do you have solution for this? – Arnold Brown May 29 '18 at 04:55
  • @ArnoldBrown, Yes I ended up taking screenshot of google maps using snapshot method. Then I took a screenshot of my Fragment and then merged them together – Akshay May 29 '18 at 21:31
  • @Akshay Merging of both is that hard? Do you have a sample to achieve this? – Arnold Brown May 30 '18 at 04:39
  • @Akshay how to merge the both. How to add the map image on particular area of the other image(in your case fragment)? – Arnold Brown May 30 '18 at 08:54
  • @ArnoldBrown I did it this way Step1: measure the height of screen Step 2 measure the height of status bar and subtract it from the the screen height, that will be the size of your App Activity. Step 3: In your activity you will know where is the start of your view where you wanted to put the Map image, then overlay it on top of it. – Akshay May 31 '18 at 01:14
  • @Akshay Will try it, thanks – Arnold Brown May 31 '18 at 03:54

0 Answers0