android - Attachments can not be sent out through email -


i trying send email attachment android app. email somehow goes out without attachment, though file exists. in email sending view, shows attachment (with file size even), after sending, on receiver side, there no attachment. idea why?

private void copyfiletoexternal() throws ioexception {     try {         file sd = environment.getexternalstoragedirectory();         file data = environment.getdatadirectory();          if (sd.canwrite()) {             string currentdbpath = "data/com.dw.inspectionhelpernstc/databases/inspection.db";             string backupdbpath = "inspection_backup.db";             file currentdb = new file(data, currentdbpath);             file backupdb = new file(sd, backupdbpath);              if (currentdb.exists()) {                 filechannel src = new fileinputstream(currentdb)                         .getchannel();                 filechannel dst = new fileoutputstream(backupdb)                         .getchannel();                 dst.transferfrom(src, 0, src.size());                 src.close();                 dst.close();                 toast.maketext(getbasecontext(), "testing", toast.length_long).show();             } else {                 toast.maketext(getbasecontext(), "not exist", toast.length_long).show();                 system.out.println("currentdb not exists");             }         } else {             toast.maketext(mainactivity.this,                     "no sdcard unable send database backup",                     toast.length_short).show();             system.out.println("sdcard cant write");         }     } catch (exception e) {         toast.maketext(getbasecontext(), "error", toast.length_long).show();         system.out.println("exception" + e.getlocalizedmessage());     } }  private void sendemail(string email) {     arraylist<uri> uris = new arraylist<uri>();     // adding inspection db;     file file = new file(environment.getexternalstoragedirectory(),             "inspection_backup.db");     uri path = uri.fromfile(file);     uris.add(path);     // adding stacttrack file uncaught expection     file file2 = new file(environment.getexternalstoragedirectory(),             constant.stacktrace_file);     uri path2 = uri.fromfile(file2);     uris.add(path2);      intent intent = new intent(android.content.intent.action_send_multiple);     intent.settype("application/octet-stream");     intent.putextra(android.content.intent.extra_subject,             "inspection database");     string to[] = { email };     intent.putextra(intent.extra_email, to);     intent.putextra(intent.extra_text,             "sending inspection database reporting");     intent.putparcelablearraylistextra(intent.extra_stream, uris);     startactivityforresult(intent.createchooser(intent, "send mail..."),             1222); } 

public void sendmailwithintent(string emailto,                                    string subject, string emailtext, list<string> filepaths) {         try {             //need "send multiple" more 1 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 arraylist             if (filepaths != null) {                 //convert paths android friendly parcelable uri's                 (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());         }      } 

call like

list<string> list = new arraylist<>();         list.add(to_attach_one);         list.add(to_attach_two);         sendmailtest.sendmailwithintent(toaddresses, subject, body, list); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -