4

我正在开发一款安卓应用程序,我在该应用程序中得到了很长的时间,并希望将其发送到电子邮件和 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

但是我们可以从这个静态网址附加图片并通过电子邮件或脸书发送...

4

1 回答 1

0

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

        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

于 2013-05-07T19:42:53.483 回答