The following is an util class for sending emails with intent. attachments can be sent.
// Mailutil. javapackage COM. maclab. util; import Java. io. file; import COM. dropbox. client2.session. session. accesstype; import android. content. context; import android. content. intent; import android. content. sharedpreferences; import android.net. uri; public class mailutil {public static void Sendmail (string path, context c) {file = new file (PATH); // The attachment file address intent = new intent (intent. action_send); intent. putextra ("subject", file. getname (); // intent. putextra ("body", "email from codepad"); // body intent. putextra (intent. extra_stream, Uri. fromfile (File); // Add an attachment. the attachment is the file object if (file. getname (). endswith (". GZ ") {intent. settype ("application/X-gzip"); // If GZ is used, use the mime of gzip} else if (file. getname (). endswith (". TXT ") {intent. settype ("text/plain"); // for plain text, use the mime of text/plain} else {intent. settype ("application/octet-stream"); // other types Use stream as binary data.} C. startactivity (intent); // call the system's mail client to send} public static void mailcontact (context c, string mailadress) {intent it = new intent (intent. action_send); string [] receiver er; receiver ER = new string [] {mailadress}; it. putextra (intent. extra_email, receiver); it. putextra ("subject", "about codepad"); it. putextra (intent. extra_text, "/* thanks advance for any tips. */"); it. settype ("text/plain"); C. startactivity (intent. createchooser (IT, "Choose email client"); // call the system's mail client to send }}
Because it is a static method, you can directly call it. Call results: