2012-10-02 5 views
0

메일에 assest 폴더 이미지 첨부 메일을 보내려고했지만 메일이 성공적으로 전송되었지만 메일에 첨부 된 이미지가 없습니다. 이것은 내 계정입니다. 코드, 당신 만 SDCARD에서 파일을 첨부 할 수 있습니다이메일에 Android assest 폴더 이미지 첨부가 실패했습니다.

Uri uri = Uri.fromFile(new File("file:///android_asset/Hat_5.png")); 

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.setType("image/png"); 
intent.putExtra(Intent.EXTRA_EMAIL , new String[] { "[email protected]"}); 
intent.putExtra(Intent.EXTRA_SUBJECT, "New Order"); 
intent.putExtra(Intent.EXTRA_TEXT , "Order Id :" +imageId); 
intent.putExtra(Intent.EXTRA_STREAM , uri); 
startActivity(Intent.createChooser(intent, "Send mail...")); 

허가

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

답변

0

. 이미지를 SDCARD로 복사하고 URI를 sdcard의 파일 경로로 변경해야합니다. 나중에 삭제할 수 있습니다.

0

당신은 ... 당신이 다음

Uri uri = Uri.fromFile(file); 
intent.putExtra(Intent.EXTRA_STREAM , uri); 

String FILENAME = "avatar.png"; 
     FileOutputStream fos = null; 

    try { 

     fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); 

    } catch (FileNotFoundException e1) { 

     e1.printStackTrace(); 
     Log.v("","FileNotFoundException: "+e1.getMessage()); 

    } 

    try { 
     InputStream inputStream = getAssets().open("avatar.jpg"); 


     byte buf[]=new byte[1024]; 
     int len; 
     while((len=inputStream.read(buf))>0) 
      fos.write(buf,0,len); 
     fos.close(); 
     inputStream.close(); 

    } catch (IOException e1) { 

     e1.printStackTrace(); 
     Log.v("","IOException: "+e1.getMessage()); 

    } 

    // Get the file from internal storage 

    String filePath = getApplicationContext().getFilesDir().getAbsolutePath();//returns current directory. 
    File file = new File(filePath, FILENAME); 

을 원하는 경우이 작업을 수행 그리고 첨부 파일을 보낼 수 있습니다

관련 문제