2014-01-17 102 views
1

我正在嘗試發送帶有聲音文件和圖像文件附件的電子郵件。我可以附加兩個文件,但是當我嘗試發送時,我正在彈出消息「不幸的是,Gmail已停止。」如何通過電子郵件附件發送音頻和圖像文件?

的代碼是在這裏: -

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
intent.setType("Audio/mp3"); 
intent.setType("image/png"); 

intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app"); 
intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file "); 

intent.putExtra(Intent.EXTRA_EMAIL, 
     new String[] { "[email protected]" }); 
ArrayList<Uri> uris = new ArrayList<Uri>(); 

uris.add(Uri.fromFile(new File(mFileName.getAbsolutePath()))); 
uris.add(Uri.parse(picturePath.toString())); 
//intent .putExtra(Intent.EXTRA_STREAM, Uri.parse(picturePath.toString())); 


intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 

// startActivity(Intent.createChooser(intent, "Send mail")); 
startActivityForResult(Intent.createChooser(intent, "Send mail"), 
     EMAIL_REQUEST); 

回答

0

發送試試這個代碼

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
emailIntent.setType("plain/text"); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"email"}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Test"); 
//has to be an ArrayList 
ArrayList<Uri> uris = new ArrayList<Uri>(); 
//convert from paths to Android friendly Parcelable Uri's 
for (String file : filePaths) 
{ 
File fileIn = new File(file); 
Uri u = Uri.fromFile(fileIn); 
uris.add(u); 
} 
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
context.startActivity(emailIntent); 
+0

不,它不適合我。 –

1

做谷歌和RND我解決了這個問題之後。遵循此代碼。

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
    intent.setType("Audio/mp3"); 
    intent.setType("image/jpg"); 
    intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app"); 
    intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file "); 
      intent.putExtra(Intent.EXTRA_EMAIL, 
      new String[] { "[email protected]" }); 
    ArrayList<Uri> uris = new ArrayList<Uri>(); 
      String[] filePaths = new String[]{mFileName.getAbsolutePath(),picturePath.toString()}; 
    for (String file : filePaths) { 
     File fileIn = new File(file); 
     Uri u = Uri.fromFile(fileIn); 
     uris.add(u); 
    } 
      intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
      startActivityForResult(Intent.createChooser(intent, "Send mail"), 
      EMAIL_REQUEST); 
    startActivityForResult(Intent.createChooser(intent, "Send mail"), 
      RESULT_LOAD_IMAGE); 
0

intent.setType("audio/mpeg")對於mp3文件,看看MIME類型!

+0

它是一個評論而不是答案 – Lrrr

0

使用settype是*。

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
intent.setType("*/*"); 


intent.putExtra(Intent.EXTRA_SUBJECT, "Attachment from app"); 
intent.putExtra(Intent.EXTRA_TEXT, "Sending mp3 file "); 

intent.putExtra(Intent.EXTRA_EMAIL, 
     new String[] { "[email protected]" }); 
ArrayList<Uri> uris = new ArrayList<Uri>(); 

uris.add(Uri.fromFile(new File(mFileName.getAbsolutePath()))); 
uris.add(Uri.parse(picturePath.toString())); 
//intent .putExtra(Intent.EXTRA_STREAM, Uri.parse(picturePath.toString())); 


intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 

// startActivity(Intent.createChooser(intent, "Send mail")); 
startActivityForResult(Intent.createChooser(intent, "Send mail"), 
     EMAIL_REQUEST); 
相關問題