通过Android应用程序共享谷歌地图静态图像

时间:2013-03-29 11:03:23

标签: android google-maps android-intent

我正在使用其中一个Android应用程序,我得到lat很长,并希望将其发送到电子邮件和Facebook

一种方法是分享谷歌静态图片网址

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

但是我们可以附加来自此静态网址的图片并通过电子邮件或Facebook发送...

1 个答案:

答案 0 :(得分:0)

以下是您可以使用的代码,基本上使用WebView拍摄快照并将其保存在某处。

        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();
                    }
}  

因此,要发送电子邮件,只需将此图片附加到电子邮件中,然后拨打电子邮件Intent