2012-03-11 92 views
3

我的应用程序中有一张可绘制图像列表,并希望通过邮件发送其中一个图像。 我的代码看起来像将可绘制图像附加到电子邮件中android

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
sendIntent.setType("image/*"); 
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Picture");      
sendIntent.putExtra(Intent.EXTRA_STREAM, 
        Uri.parse(lstPhotos.get(newPosition).getPhotoURL())); 
myActivity.startActivity(Intent.createChooser(sendIntent, "Email:")); 

但在上面的代码中,我有一个问题,因为我无法从绘图资源列表中获取图像URI。 任何人都可以帮助我如何发送图像,因为如果我使用上面的代码,我得到一个0kb的空图像发送。

回答

1

您可以通过图像保存到一个临时位置上的内部/外部缓存目录为图像做出来,然后使用该图片的路径,使用乌里附件。

-1

你也可以试试这个:

URL url = new URL(lstPhotos.get(newPosition).getPhotoURL()); 
Bitmap bm = BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); 
File file = new File(extStorageDirectory, "MyIMG.png"); 
FileOutputStream outStream = null; 
try { 
    outStream = new FileOutputStream(file); 
    bm.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
    outStream.flush(); 
    outStream.close(); 
} catch (FileNotFoundException e) { 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 
Uri imguri = Uri.fromFile(file); 
相关问题