2011-01-23 112 views

回答

9

然后,您必须将位图保存到SDCard,然后将其附加到电子邮件(我猜你know how to do so)。

为什么需要将其保存到SDCard?这是因为电子邮件应用程序将不得不阅读将要附加的文件;因此,您必须将路径和文件名传递给电子邮件客户端。与其他应用程序一样,电子邮件客户端只能访问存储在其私人目录或SDCard中的文件。

+0

Thanx的信息。有没有什么办法可以直接发送位图对象,而不是将它保存到SD卡中?我不希望图像可供其他应用程序或用户访问。 – mobiledev 2011-01-23 19:27:57

+0

您可以在电子邮件发送后删除图像。 – Cristian 2011-01-23 19:29:57

4
/* Return Drawable Object from Specified imageUrl In Web 

@imageUrl : image Url in Web 

*/ 

try { 
/// Getting image from Web 
    InputStream is = (InputStream) new URL(imageUrl).getContent(); 
    // storing image from stream 
    drawable = Drawable.createFromStream(is, "srcName"); 
    is.close(); 
    // converting drawable object to Bitmap to store in content providers of Media 
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); 
    // Store image in Devise database to send image to mail 
    String path = Images.Media.insertImage(getContentResolver(), bitmap,"title", null); 
    Uri screenshotUri = Uri.parse(path); 
    final Intent emailIntent1 = new Intent( android.content.Intent.ACTION_SEND); 
    emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    emailIntent1.putExtra(Intent.EXTRA_STREAM, screenshotUri); 
    emailIntent1.setType("image/png"); 
    startActivity(Intent.createChooser(emailIntent1, "Send email using")); 

} 
catch(Exception e) { } 
相关问题