2015-07-07 9 views
11

Ja załączając plik tekstowy na e-mail z kodem:Attachment nie przychodzi w poczcie programowo

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", 
            "[email protected]", null)); 

    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Report"); 

    emailIntent.putExtra(Intent.EXTRA_TEXT, prepareBodyMail()); 
    File root = Environment.getExternalStorageDirectory(); 
    File file = new File(root, "/MyFolder/report.txt"); 

    Uri uri = Uri.fromFile(file); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri); 
    startActivity(Intent.createChooser(emailIntent, "Pick an Email provider")); 

ten kod działa doskonale z Gmail, poczta elektroniczna i inne aplikacje

Ale to nie jest dołączenie złożyć INBOX aplikacji przez Google

Tylko Ciało i podlega idą bez przywiązania

Zgłosiłem ten problem do Grup dyskusyjnych Google pod numerem Inbox Problem

Czy ktoś może pomóc w tym, czego mi brakuje w kodzie?

+0

hej Czy miałeś stałe swój problem lub nadal szukają. wypróbuj moje rozwiązanie, mam nadzieję, że to zadziała. –

+0

Wciąż szukam rozwiązania. Zgłaszałem problem także grupom Google. Mam nadzieję, że zostanie to rozwiązane. – Kushal

+1

Ten sam problem dla mnie, nie udało mi się znaleźć rozwiązanie w dowolnym miejscu. – Kage

Odpowiedz

0
String fileLocation = Environment.getExternalStorageDirectory() + "/MyFolder/report.txt";  
String to[] = {"[email protected]"}; 

Intent intentEmail = new Intent(Intent.ACTION_SEND); 
intentEmail.setType("vnd.android.cursor.dir/email"); 
intentEmail.putExtra(Intent.EXTRA_EMAIL, to); 
intentEmail.putExtra(Intent.EXTRA_STREAM, fileLocation); 
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "Subject"); 

startActivity(Intent.createChooser(intentEmail , "Pick an Email provider")); 
+0

To również nie działa z aplikacją Inbox. Myślę, że powinniśmy podać parametr Uri typu wirh Intent.EXTRA_STREAM kay in intent .. To jest problem w kodzie – Kushal

1

Try This

 Uri myUri = Uri.parse("file://" + path); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, myUri); 
+0

To nie działa z załącznikiem aplikacji Inbox .. – Kushal

0
Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setType("text/plain"); 
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"}); 
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here"); 
intent.putExtra(Intent.EXTRA_TEXT, "body text"); 
File root = Environment.getExternalStorageDirectory(); 
File file = new File(root, xmlFilename); 
if (!file.exists() || !file.canRead()) { 
    Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show(); 
    finish(); 
    return; 
} 
Uri uri = Uri.fromFile("file://" + file); 
intent.putExtra(Intent.EXTRA_STREAM, uri); 
startActivity(Intent.createChooser(intent, "Send email...")); 
+0

To działa dla Gmaila, aplikacji pocztowych, ale nie działa z aplikacją Inbox. – Kushal

+0

OK, edytujesz pytanie pozwól mi sprawdzić –

+0

Wspomniałem już, że mój kod działa z Gmailem i pocztą e-mail, ale nie z Inbox .. – Kushal

0
public void sendMailWithIntent(String emailTo, 
            String subject, String emailText, List<String> filePaths) { 
     try { 
      //need to "send multiple" to get more than one attachment 
      final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
      emailIntent.setType("text/plain"); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
        Util.extractEmails(emailTo)); 
//   emailIntent.putExtra(android.content.Intent.EXTRA_CC, 
//     new String[]{emailCC}); 
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 
      emailIntent.putExtra(Intent.EXTRA_TEXT, emailText); 
      ArrayList<Uri> uris = new ArrayList<Uri>(); 
      //has to be an ArrayList 
      if (filePaths != null) { 
       //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); 
      Intent chooser = Intent.createChooser(emailIntent, "Send mail..."); 
      activity.startActivityForResult(chooser, 1); 
     } catch (Exception e) { 
      new ShowToast(context, e.getMessage()); 
     } 

    } 

wywołać metodę

List<String> list = new ArrayList<>(); 
    list.add(TO_ATTACH_ONE); 
    list.add(TO_ATTACH_TWO); 
    sendMailWithIntent(toAddresses, subject, body, list); 
+0

To nie działa dla aplikacji Inbox .. – Kushal

Powiązane problemy