2012-03-11 7 views
3

私は自分のアプリケーションにDrawableイメージのリストを持っており、そのイメージの1つをメールで送信したいと考えています。 私のコードはアンドロイドで電子メールに描画可能なイメージを添付する

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); 
関連する問題