Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

android - Attaching file in email

I am sending email by attaching file with the email in the following code. I am unable to get the right email in my inbox in the return

Intent intent = new Intent(Intent.ACTION_SEND); 
               intent.setType("image/jpeg");
               intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);  
               intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); 
               intent.putExtra(Intent.EXTRA_TEXT, emailText); 
               intent.putExtra(Intent.EXTRA_TEXT, emailText); 
               intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.pic));
               Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.pic));
               startActivity(Intent.createChooser(intent, "Choice App to send email:"));

In the inbox the result is like that instead of an image.

???H??? !1AQaq?"?2??B#??Rb3?r??CS$?c????%!1AQq"2aB#????T@?? pJ?=>?
?
???` pH?`?A00V??7LM??????H????]w?v??峆????щ?9N!?*y???k???_?{b?p[y8?~Le??>??m????#??1??.W?w???oj???7?8?#?s?V?U??j?Q???m??0??~*S2?:V6??O?&|Dj?h??+U?xy.?Q?B?;
M   ???b????`v?v*?tgT??oX?Cf???)[??Io!F?v????{cT269???v6X8????????*S??@???A ? H$s?@? ?@? ?-?b?? ??i@?P8iA H5?A H?
h3B???W???Km?:??EFc?????x?????b,?$?H` ?
j?x}?m<1??
u?Z;?,???????G????*Q?%????/SL?u???x ?c^?з#????lP?T?mK|??????h?/?Lp4?T4;?MWI?a'???Z???y???7MV?FZ?E?#5??g??y?OL??????.??Os3??h?n??d? ?@???A ? H$2A??I???M?I?th@?(j??>?H?A U???c??_A?????x-G??#asY?B??>?=I??n3??ù?9?F,yq?A??x??/??c
??z?鄛??0`?~Q^?????s:"m-?8???8&???o????XH?a9????-??n<??X?Y?}?YD?D???N?V??ne????5??;74?H?VR???
????k@p???w%?~Z?O?9l?^[?????8w??U{Ei???t?DP???y>G8.?<??m?VSP? v???C$???``??@? ?B    Q??@? z ??$ P ?5??
?i?A??=?R<??[?^n[,?Pz?H_j"????cZMr!y?H?s??}????[_??la??H??{?Y?S?o?4;?-??haqk^d??:F,??[?3??{t^??j?X??n&?n??<??9?s_??k;LV?,???????d???D??L?]p???s??T??+?e?=?6? ?m.?(
#Igh?YZ???A????W8<?c?"??]$f?m??m??y??H=??+X?????Q??|????X????v??6?
:?????~??O???h
?HD?? ?@?@? ?s? ?$?@??TA 0A&???=*@? ?J  ??H4?p;?e?]??;h?3??iq??5?=????Π???]r?]??+?/?????y????絊[s`m(?fff?+?z??&p5?*?0??????!r?Y^??m<??:On?f?4??????H]?X???n?}?-??2i?????;l-?y?4?R?q=??>??0u?&k??? U??^j??&???Q?{;e?/???>?e}g??-??A?w?Z?6^?????^???????[?-*????onR0=1?????gl?[?;?w???j?Q???X??]???].??%y?G?*?;???0?p?A?H$??A HI??BA* p* ?$  ??@? ?$??pgMo&?????Vw????s?`??|???m_{p-?t?%?PjI"?.k?????nv????????????70?p ???p?yiV????~bGeW?????;???7?r???mY?(?,?9?B^N??$Q??*Us??}????.q36"<′?O???:??!???T??X??1?S???:i??N?????K????S7p?Ml??};0?I???g??+??r??b9????N{?-;)????>w?K?l???|?R$$L H????s???    ?H?@?b?a?A* z pH?@ pJ?$oT???9W??7?,????O?úg?o??d?????Kv??N1?8s^g[????{ ????h?k*94??V?^g??)w????nG;??h(???./????m?z????nd???{?Z;???^??#do?E<??F????Q????y!???R?S?
?^z[O??k<?;x#?????T?'?}???v??sV??' t?????A??     ???A0L ?A 8$??@?A Q??:?e????K?9?`?gF?}?m<5??k??:??j????o.c??5?
x/
????:??Po??M????HY_[lp?|??c?F???^??q,>f??-s{9k8yw?d???i?aZ?Bd ???k67*??R}????na??F?n`?J??k[?T1]?8?d??IF?3?WI?u??2??,"????u??g????侞??a??7"?????8A ??I?  ?   ?B????  ?   ?&*?mA H({PHD?????5ι?4y?@?T??R?=?T?YY?V?!?
l???xz?????>hΖD????9?s?[??E?m??G??  dn9?!#????S???nYQB|??
U?眵?hxp9????5I%Z<?:?ZV?,o???y$?y`f???????y>?O?.*???@??   t t$?A x ?$3A. ?&  ??` ?A ?`?rD67??~$?e88?????N?j?
?d??2n????Iu??Q?pTi???????w#k??0?0?????????b????m?q???W??!??x?U????VH?M???DM2?!.{??*]??R?=<???$vM??y???[?0<?d6?|WM$?P?H??I?4?7}????F?3?Z??????l??V4>??$?%L?m??n????q?Q?r?-
h?b?}?R???d.=??>?????????×w???=H p??8@?8@???*?? ? ?A6??? ?&?P)f??????f?Y?1???Hh?1??U?q^??QXApa魏?!f???0???i????~????0??P?>???]?+??I?o?yy?k?I?kZ;?+?x??RN???C?????c~???p????d?0ET'49???q%ē~*d;p??}?v?}I?p?o?=??????????*/
?_KY?z?|??????>?n???????hd???2???ur|[?Ot?w???3????j???9??Ci?b??0dDMk0??f??L?#?6u?3?{, ???W????|??? ???v??p??@?@????|
    ?m(,??A I???    7$?F?:??bjJ0???M??b?fs:kn????????f?J4-???B?b??
??t??
-???,?tT+8?8?S#??   yv?j?;
????=????aE????8y???n.?P?asw?????'?ykB?b????
o??i?NV2N|?n?s?BEZ?U????y?????m?.???w:;c?]??o???N?m?$3>?zC(??sEX?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this out -

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);

And, also just refer previous question on Stackoverflow about attach the images in Email through Intent.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...