Trying to implement the Share Intent

3510
9
05-24-2012 07:32 AM
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
I am trying to implement the Android Share Intent in order to share out a screen shot of my map via email, facebook, twitter, etc.  My thought was to export out the View as a jpg, then attach it.  I'm able to export out the view, but the map shows up as black.  Every other view element shows up - except for the map.
Here's my code:
View content = findViewById(R.id.mainlayout);   content.setDrawingCacheEnabled(true);
   Bitmap b = content.getDrawingCache();
   File sdCard = Environment.getExternalStorageDirectory();
   File file = new File(sdCard,"zzImage.jpg");
     if(file.exists()){
      file.delete();
     }    
   try {
    b.compress(CompressFormat.JPEG, 100, new FileOutputStream(file));
   } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } 


I have also attached two images.  One of what it's supposed to look like, and one of the results from the above code.

Any ideas?
[ATTACH=CONFIG]14605[/ATTACH][ATTACH=CONFIG]14606[/ATTACH]
0 Kudos
9 Replies
AndyGup
Esri Regular Contributor
Andrew, sorry I can't help with that. Serializing screen captures on any client is tricky because issues related to Class reflection. The usual best practice is to create a URL to an external web map.

-Andy
0 Kudos
by Anonymous User
Not applicable
Original User: andrewb

Too bad.  I'd really like to try to find a workaround for this. I was hoping to "cheat" by just attaching a screen shot.  that way it'll share exactly what the end user is viewing.  It's odd how everything BUT the map gets exported.  I tried writing out just the map to a bitmap as opposed to the entire layout. that came out just black too.  Could it have something to do with the implementation of OpenGL as part of the MapView?
0 Kudos
AndyGup
Esri Regular Contributor
I'm just guessing that this has do with MapView when you serialize/deserialize it as a bitmap at the bytecode level. Did you try any patterns similar to this link: http://www.brighthub.com/mobile/google-android/articles/30676.aspx?

-Andy
0 Kudos
by Anonymous User
Not applicable
Original User: andrewb

I'm just guessing that this has do with MapView when you serialize/deserialize it as a bitmap at the bytecode level. Did you try any patterns similar to this link: http://www.brighthub.com/mobile/google-android/articles/30676.aspx?

-Andy


I tried, and wasn't successful.  honestly, I had a hard time following the article. 

Any other suggestions?  Seems like no matter what I try (and I've tried a lot of patterns), all I get is a black image.

Thanks,
Andrew
0 Kudos
AndyGup
Esri Regular Contributor
Another thought is that your drawing cache may be defaulting to a width/height of 0,0. According to the Android docs you may be missing a call to createBitmap(). And, that method calls for a width, height and Bitmap.Config.

Here's a code snippet that will hopefully re-point you down the right track:

View map = findViewById(R.id.map);
bitmap = Bitmap.createBitmap(map.getWidth(), map.getHeight(), Bitmap.Config.RGB_565);


If you already tried this, can you list out what patterns you've tried?

-Andy
0 Kudos
by Anonymous User
Not applicable
Original User: andrewb

Another thought is that your drawing cache may be defaulting to a width/height of 0,0. According to the Android docs you may be missing a call to createBitmap(). And, that method calls for a width, height and Bitmap.Config.

Here's a code snippet that will hopefully re-point you down the right track:

View map = findViewById(R.id.map);
bitmap = Bitmap.createBitmap(map.getWidth(), map.getHeight(), Bitmap.Config.RGB_565);


If you already tried this, can you list out what patterns you've tried?

-Andy


Andy,
Same Result - black image.

I've tried exporting out just the mapView as a bitmap, the entire layout as a bitmap, using different bitmap configurations, using different output image types (jpg, png), moving the view onto a canvas.  None seem to be working.

My current workaround is to get the minx/y, max x/y map extent and pass it to the REST endpoint and return an image.  Downside to this is I don't have the graphicslayer overlaid, or the callout.  I'm trying to figure out a way to write the callout to a separate bitmap as well as the graphicslayer(if possible) and overlay them all. Its a ton of work just to do a simple screen shot, but as of now at least I have a map.  callout and graphicslayer is hopefully the next step.  Downside is this requires another round trip to the server.
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
After a little digging, It looks like I'm not the only one with this issue.  I found this thread:
http://forums.arcgis.com/threads/46792-mapview.getMapDrawingCache()-returns-null

Has this been confirmed as a bug?
0 Kudos
by Anonymous User
Not applicable
Original User: andygup

Yes, it's been confirmed there is a bug. Please refer to Archana's comment here that includes a potential workaround: http://forums.arcgis.com/threads/46792-mapview.getMapDrawingCache()-returns-null?p=202231#post202231

-Andy
0 Kudos
AndyGup
Esri Regular Contributor
For those who this bug applies to it has been logged under NIM081315.

-Andy
0 Kudos