【问题标题】:Sharing google map static image via android app通过安卓应用分享谷歌地图静态图片
【发布时间】:2013-03-20 01:53:54
【问题描述】:

我正在开发一款 Android 应用程序,我想把它发送到电子邮件和 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 发送...

【问题讨论】:

  • 对于 facebook,您可以使用图形 API 直接使用 URL。但是对于电子邮件,您必须将位图保存在设备中,或者只需将 url 发送到邮件中。
  • 感谢,根据他们的设计,fb 上的意图是不可能的,所以我将尝试使用 fb android sdk 的图形 api,对于其他电子邮件,我将首先将位图保存在设备上,然后附加,感谢分享信息.... .

标签: android google-maps android-intent


【解决方案1】:

这是您可以使用的代码,基本上是使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多