2012-03-06 17 views
5

Birkaç dosyaya e-posta ile göndermek istiyorum. Bu Android multiple email attachments using Intent buldum ama işe yaramıyor ve herhangi bir hata iletisi almıyorum. Sadece dosyaları eklemiyorum (sadece bir dosya göndermeye çalıştım ama aynı sonucu aldım).Android Amaç: eki ile bir e-posta gönderin

Bir şeyleri inceledim mi? Önerin var mı?

private static void email (Context context, String emailTo, String emailCC, 
    String subject, String emailText, List<String> filePaths) 
{ 
    //need to "send multiple" to get more than one attachment 
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
    emailIntent.setType("text/xml"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
     new String[]{emailTo}); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText); 
    //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); 
     Uri u = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "blabla.xml")); 
     Log.v("bla", "filepath: " +u.toString()); 
     uris.add(u); 
     Uri b = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "blabla.es")); 
     uris.add(b); 
     Log.v("bla", "filepath: " +b.toString()); 
    } 
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
    context.startActivity(emailIntent); 
} 

LogCat:

03-06 16:08:50.940: INFO/ActivityManager(69): Starting: Intent { act=android.intent.action.SEND_MULTIPLE typ=text/xml cmp=com.android.email/.activity.MessageCompose (has extras) } from pid 436 
03-06 16:08:52.130: INFO/ActivityManager(69): Displayed com.android.email/.activity.MessageCompose: +1s118ms 
03-06 16:08:52.470: WARN/IInputConnectionWrapper(436): showStatusIcon on inactive InputConnection 
+0

Açıkçası, ancak dosya yollarınızın doğru olduğundan ve gerçek dosyalara işaret ettiğinden emin misiniz? – dymmeh

+0

dosya yolları doğru – user1252642

+1

Çoğu e-posta programı 'text/xml' MIME türlerini işleyemez. Dahası, çoğu kullanıcı XML okuyamıyor. Lütfen bunun yerine 'text/plain' veya' text/html' email prose'u kullanmayı düşünün. – CommonsWare

cevap

1

Bu kod benim için çalışıyor. pdfFiles, ArrayList<Uri> tipindedir.

  Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
      shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getText(R.string.share_subject)); 
      CharSequence seq = Html.fromHtml(mOCRText.toString()); 
      shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, seq); 
      shareIntent.setType("application/pdf"); 

      shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, pdfFiles); 
      startActivity(Intent.createChooser(shareIntent, getText(R.string.share_chooser_title)));