Sharing a Google Map still image using an Android app

I am working on one of the Android applications where I get lat long and want to send it by email and facebook

one way is to distribute google static image url

http://maps.googleapis.com/maps/api/staticmap?center=63.259591,-144.667969&zoom=6&size=400x400%20&markers=color:blue%7Clabel:S%7C62.107733,-145.541936&zoom=15&sensor=false

but we can attach an image from this static URL and send it by email or facebook ...

+4
source share
1 answer

Here is the code you can use, basically use WebView to take a snapshot and save it somewhere.

  private static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable){ Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pictureDrawable.getPicture()); return bitmap; } public void getImage() { WebView web=(WebView)findViewById(R.id.your_webviews_id); Picture p=web.capturePicture(); SharedPreferences prefs=con.getSharedPreferences("File_COUNT", con.MODE_PRIVATE); //int count=prefs.getInt(//"COUNT", 0); long rand= System.currentTimeMillis(); File root=new File(Environment.getExternalStorageDirectory()+"/Maps"); root.mkdirs(); File save_img=new File(root.getAbsolutePath()+"/"+rand+".png"); //OutputStream os; try { Bitmap bmp = pictureDrawable2Bitmap(new PictureDrawable(p)); FileOutputStream out = new FileOutputStream(save_img.getAbsolutePath()); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); Toast.makeText(con, "Save successful", Toast.LENGTH_SHORT).show(); Intent shareIntent = new Intent(Intent.ACTION_SEND); MimeTypeMap mime = MimeTypeMap.getSingleton(); String type = mime.getMimeTypeFromExtension("png"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(save_img)); shareIntent.setType(type); startActivity(Intent.createChooser(shareIntent, "Share Using")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block Toast.makeText(con, "File not able to be saved. Please restart app", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(con, "I/O error", Toast.LENGTH_SHORT).show(); } } 

Therefore, to send an email, simply attach this image to your email and call Intent email.

0
source

All Articles