2012-10-19 4 views
1

드로어 블 폴더에서 이미지를 첨부하여 이메일로 보내드립니다. 기본 이메일 클라이언트에서 보낼 때 이미지 확장자 (.png)가 첨부 파일 에없고 파일 이름 자체가 변경되었습니다. 기본 이름 (드로어 블 에서처럼)과 .png 확장자로 이미지를 보내려고합니다.android에서 드로어 블에서 이미지를 첨부하는 방법

이것은 내 코드입니다.

Intent email = new Intent(Intent.ACTION_SEND); 
      email.setType("image/png"); 

      email.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); 

      email.putExtra(Intent.EXTRA_SUBJECT, "Hey! "); 


      email.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher)); 
startActivity(Intent.createChooser(email, "Sending........")); 

이 코드에 감사를 worng 무엇 저를 제안하십시오.

답변

1

이미지가 SDCARD에있는 경우에만 메일에 이미지를 첨부 할 수 있습니다. 이미지를 SD로 복사 한 다음 첨부해야합니다.

InputStream in = null; 
OutputStream out = null; 
try 
{ 
in = getResources().openRawResource(R.raw.ic_launcher); 
out = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "image.png")); 
copyFile(in, out); 
in.close(); 
in = null; 
out.flush(); 
out.close(); 
out = null; 
} 
catch (Exception e) 
       { 
        Log.e("tag", e.getMessage()); 
        e.printStackTrace(); 
       } 

private void copyFile(InputStream in, OutputStream out) throws IOException 
    { 
     byte[] buffer = new byte[1024]; 
     int read; 
     while ((read = in.read(buffer)) != -1) 
     { 
      out.write(buffer, 0, read); 
     } 
    } 


Intent emailIntent = new Intent(Intent.ACTION_SEND); 
       emailIntent.setType("text/html"); 
       emailIntent.putExtra(Intent.EXTRA_SUBJECT, "File attached"); 
       Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "image.png")); 
       emailIntent.putExtra(Intent.EXTRA_STREAM, uri); 
       startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
+0

일부 코드를 보내주십시오. – mukesh

+0

수정 된 답변 – Givi

+0

감사 문제가 해결되었습니다. – mukesh

관련 문제