List of usage examples for android.content Intent EXTRA_EMAIL
String EXTRA_EMAIL
To view the source code for android.content Intent EXTRA_EMAIL.
Click Source Link
From source file:com.android.mail.compose.ComposeActivity.java
/** * Fill all the widgets with the content found in the Intent Extra, if any. * Also apply the same style to all widgets. Note: if initFromExtras is * called as a result of switching between reply, reply all, and forward per * the latest revision of Gmail, and the user has already made changes to * attachments on a previous incarnation of the message (as a reply, reply * all, or forward), the original attachments from the message will not be * re-instantiated. The user's changes will be respected. This follows the * web gmail interaction./*w w w . j a v a 2 s. c o m*/ * @return {@code true} if the activity should not call {@link #finishSetup}. */ public boolean initFromExtras(Intent intent) { // If we were invoked with a SENDTO intent, the value // should take precedence final Uri dataUri = intent.getData(); if (dataUri != null) { if (MAIL_TO.equals(dataUri.getScheme())) { initFromMailTo(dataUri.toString()); } else { if (!mAccount.composeIntentUri.equals(dataUri)) { String toText = dataUri.getSchemeSpecificPart(); if (toText != null) { mTo.setText(""); addToAddresses(Arrays.asList(TextUtils.split(toText, ","))); } } } } String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL); if (extraStrings != null) { addToAddresses(Arrays.asList(extraStrings)); } extraStrings = intent.getStringArrayExtra(Intent.EXTRA_CC); if (extraStrings != null) { addCcAddresses(Arrays.asList(extraStrings), null); } extraStrings = intent.getStringArrayExtra(Intent.EXTRA_BCC); if (extraStrings != null) { addBccAddresses(Arrays.asList(extraStrings)); } String extraString = intent.getStringExtra(Intent.EXTRA_SUBJECT); if (extraString != null) { mSubject.setText(extraString); } for (String extra : ALL_EXTRAS) { if (intent.hasExtra(extra)) { String value = intent.getStringExtra(extra); if (EXTRA_TO.equals(extra)) { addToAddresses(Arrays.asList(TextUtils.split(value, ","))); } else if (EXTRA_CC.equals(extra)) { addCcAddresses(Arrays.asList(TextUtils.split(value, ",")), null); } else if (EXTRA_BCC.equals(extra)) { addBccAddresses(Arrays.asList(TextUtils.split(value, ","))); } else if (EXTRA_SUBJECT.equals(extra)) { mSubject.setText(value); } else if (EXTRA_BODY.equals(extra)) { setBody(value, true /* with signature */); } else if (EXTRA_QUOTED_TEXT.equals(extra)) { initQuotedText(value, true /* shouldQuoteText */); } } } Bundle extras = intent.getExtras(); if (extras != null) { CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT); setBody((text != null) ? text : "", true /* with signature */); // TODO - support EXTRA_HTML_TEXT } mExtraValues = intent.getParcelableExtra(EXTRA_VALUES); if (mExtraValues != null) { LogUtils.d(LOG_TAG, "Launched with extra values: %s", mExtraValues.toString()); initExtraValues(mExtraValues); return true; } return false; }
From source file:ua.mkh.settings.full.MainActivity.java
public void send_email() { final Dialog Activation = new Dialog(MainActivity.this, android.R.style.Theme_Translucent); Activation.requestWindowFeature(Window.FEATURE_NO_TITLE); Activation.setContentView(R.layout.dialog_inform); // set the custom dialog components - text, image and button Button dialogButton12 = (Button) Activation.findViewById(R.id.dialogButtonOK); TextView textf = (TextView) Activation.findViewById(R.id.textBold); TextView textverf = (TextView) Activation.findViewById(R.id.text); dialogButton12.setTypeface(typefaceRoman); textf.setTypeface(typefaceBold);/* ww w . j a v a 2 s . c om*/ textverf.setTypeface(typefaceRoman); textverf.setText(R.string.activation); // if button is clicked, close the custom dialog dialogButton12.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (YA != null && G != null) { Intent i2 = new Intent(Intent.ACTION_SEND); i2.setType("text/rfc822"); i2.putExtra(Intent.EXTRA_EMAIL, new String[] { "maxim.khaydarov@yandex.ru" }); i2.putExtra(Intent.EXTRA_SUBJECT, "Activation"); i2.putExtra(Intent.EXTRA_TEXT, "2: " + codes(YA) + "\n" + "1: " + codes(G)); Editor e = mSettings.edit(); e.putBoolean(APP_PREFERENCES_ACTIVATION, true); e.commit(); // ? try { startActivity(Intent.createChooser(i2, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, "No email clients installed.", Toast.LENGTH_SHORT).show(); Editor e1 = mSettings.edit(); e1.putBoolean(APP_PREFERENCES_ACTIVATION, false); e1.commit(); // ? } } Editor e = mSettings.edit(); e.putBoolean(APP_PREFERENCES_ACTIVATION, true); e.commit(); // ? Activation.dismiss(); } }); Activation.show(); }
From source file:com.jtschohl.androidfirewall.MainActivity.java
/** * Email error reports//from w w w . j a v a 2 s. c om */ private void emailErrorReports() { File sdCard = Environment.getExternalStorageDirectory(); File dir = new File(sdCard.getAbsolutePath() + "/af_error_reports/"); String filename = "af_error_reports.zip"; File file = new File(dir, filename); String af_version; try { af_version = getApplicationContext().getPackageManager() .getPackageInfo(getApplicationContext().getPackageName(), 0).versionName; } catch (NameNotFoundException e) { af_version = "Unknown"; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "androidfirewall.developer@gmail.com" }); intent.putExtra(Intent.EXTRA_SUBJECT, "Android Firewall Error Report for version " + af_version); intent.putExtra(Intent.EXTRA_TEXT, ""); if (!file.exists() || !file.canRead()) { Toast.makeText(this, R.string.no_zip, Toast.LENGTH_SHORT).show(); Log.d(TAG, "No zip file is available"); finish(); return; } Uri uri = Uri.fromFile(file); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(intent, getString(R.string.send_email))); return; }
From source file:com.tct.mail.compose.ComposeActivity.java
/** * Fill all the widgets with the content found in the Intent Extra, if any. * Also apply the same style to all widgets. Note: if initFromExtras is * called as a result of switching between reply, reply all, and forward per * the latest revision of Gmail, and the user has already made changes to * attachments on a previous incarnation of the message (as a reply, reply * all, or forward), the original attachments from the message will not be * re-instantiated. The user's changes will be respected. This follows the * web gmail interaction.//from w w w . java 2 s . co m * @return {@code true} if the activity should not call {@link #finishSetup}. */ public boolean initFromExtras(Intent intent) { // If we were invoked with a SENDTO intent, the value // should take precedence final Uri dataUri = intent.getData(); if (dataUri != null) { if (MAIL_TO.equals(dataUri.getScheme())) { initFromMailTo(dataUri.toString()); } else { if (!mAccount.composeIntentUri.equals(dataUri)) { String toText = dataUri.getSchemeSpecificPart(); // TS: junwei-xu 2015-03-23 EMAIL BUGFIX_980239 MOD_S //if (toText != null) { if (Address.isAllValid(toText)) { // TS: junwei-xu 2015-04-23 EMAIL BUGFIX_980239 MOD_E mTo.setText(""); addToAddresses(Arrays.asList(TextUtils.split(toText, ","))); } } } } String[] extraStrings = intent.getStringArrayExtra(Intent.EXTRA_EMAIL); if (extraStrings != null) { addToAddresses(Arrays.asList(extraStrings)); } extraStrings = intent.getStringArrayExtra(Intent.EXTRA_CC); if (extraStrings != null) { addCcAddresses(Arrays.asList(extraStrings), null); } extraStrings = intent.getStringArrayExtra(Intent.EXTRA_BCC); if (extraStrings != null) { addBccAddresses(Arrays.asList(extraStrings)); } String extraString = intent.getStringExtra(Intent.EXTRA_SUBJECT); if (extraString != null) { mSubject.setText(extraString); } for (String extra : ALL_EXTRAS) { if (intent.hasExtra(extra)) { String value = intent.getStringExtra(extra); if (EXTRA_TO.equals(extra)) { addToAddresses(Arrays.asList(TextUtils.split(value, ","))); } else if (EXTRA_CC.equals(extra)) { addCcAddresses(Arrays.asList(TextUtils.split(value, ",")), null); } else if (EXTRA_BCC.equals(extra)) { addBccAddresses(Arrays.asList(TextUtils.split(value, ","))); } else if (EXTRA_SUBJECT.equals(extra)) { mSubject.setText(value); } else if (EXTRA_BODY.equals(extra)) { //[BUGFIX]-Add-BEGINbySCDTABLET.yafang.wei,07/21/2016,2565329 // Modifytofixsignatureshowsbeforebodyissuewhensharewebsitebyemail if (mBodyView.getText().toString().trim() .equals(convertToPrintableSignature(mSignature).trim())) { mBodyView.setText(""); setBody(value, true /* with signature */); appendSignature(); } else { setBody(value, true /* with signature */); } //[BUGFIX]-Add-ENDbySCDTABLET.yafang.wei } else if (EXTRA_QUOTED_TEXT.equals(extra)) { initQuotedText(value, true /* shouldQuoteText */); } } } Bundle extras = intent.getExtras(); //[BUGFIX]-MOD-BEGIN by TSNJ,wenlu.wu,10/20/2014,FR-739335 if (extras != null && !mBodyAlreadySet) { //[BUGFIX]-MOD-END by TSNJ,wenlu.wu,10/20/2014,FR-739335 CharSequence text = extras.getCharSequence(Intent.EXTRA_TEXT); //[BUGFIX]-Add-BEGINbySCDTABLET.yafang.wei,07/21/2016,2565329 // Modifytofixsignatureshowsbeforebodyissuewhensharewebsitebyemail if (mBodyView.getText().toString().trim().equals(convertToPrintableSignature(mSignature).trim())) { mBodyView.setText(""); setBody((text != null) ? text : "", true /* with signature */); appendSignature(); } else { setBody((text != null) ? text : "", true /* with signature */); } //[BUGFIX]-Add-ENDbySCDTABLET.yafang.wei // TODO - support EXTRA_HTML_TEXT } mExtraValues = intent.getParcelableExtra(EXTRA_VALUES); if (mExtraValues != null) { LogUtils.d(LOG_TAG, "Launched with extra values: %s", mExtraValues.toString()); initExtraValues(mExtraValues); return true; } return false; }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void sendLogMail(String file, String type) { final File path = IOUtils.getDownloadDirectory(getApplicationContext()); File logFile = new File(path, file); if (logFile.isFile()) { Intent sendMail = new Intent(Intent.ACTION_SEND); String subject = getString(R.string.log_send_mail_subject).replace("{0}", type); String text = getString(R.string.log_send_mail_content).replace("{0}", type); sendMail.putExtra(Intent.EXTRA_EMAIL, new String[] { "android@tvbrowser.org" }); sendMail.putExtra(Intent.EXTRA_SUBJECT, subject); sendMail.putExtra(Intent.EXTRA_TEXT, text + " " + new Date().toString()); sendMail.setType("text/rtf"); sendMail.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + logFile.getAbsolutePath())); startActivity(Intent.createChooser(sendMail, getResources().getString(R.string.log_send_mail))); } else {/*from w w w . j ava 2 s . co m*/ AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); builder.setTitle(R.string.no_log_file_title); builder.setMessage(R.string.no_log_file_message); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); builder.show(); } }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc//from w w w . j a v a 2s .c om */ public void sendMessage(String[] recipients, String subject, Message msg) { if (editInProgress()) { stopEditing(true); } Intent emailIntent; String attachment = msg.getAttachment(); boolean hasAttachment = (attachment != null && attachment.length() > 0) || msg.getAttachments().size() > 0; if (msg.getMimeType().equals(Message.MIME_TEXT) && !hasAttachment) { StringBuilder to = new StringBuilder(); for (int i = 0; i < recipients.length; i++) { to.append(recipients[i]); to.append(";"); } emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + to.toString() + "?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(msg.getContent()))); } else { if (hasAttachment) { if (msg.getAttachments().size() > 1) { emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.setType(msg.getMimeType()); ArrayList<Uri> uris = new ArrayList<Uri>(); for (String path : msg.getAttachments().keySet()) { uris.add(Uri.parse(fixAttachmentPath(path))); } emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } else { emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.setType(msg.getMimeType()); emailIntent.setType(msg.getAttachmentMimeType()); //if the attachment is in the uder home dir we need to copy it //to an accessible dir attachment = fixAttachmentPath(attachment); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(attachment)); } } else { emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.setType(msg.getMimeType()); } if (msg.getMimeType().equals(Message.MIME_HTML)) { emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg.getContent())); } else { /* // Attempted this workaround to fix the ClassCastException that occurs on android when // there are multiple attachments. Unfortunately, this fixes the stack trace, but // has the unwanted side-effect of producing a blank message body. // Same workaround for HTML mimetype also fails the same way. // Conclusion, Just live with the stack trace. It doesn't seem to affect the // execution of the program... treat it as a warning. // See https://github.com/codenameone/CodenameOne/issues/1782 if (msg.getAttachments().size() > 1) { ArrayList<String> contentArr = new ArrayList<String>(); contentArr.add(msg.getContent()); emailIntent.putStringArrayListExtra(android.content.Intent.EXTRA_TEXT, contentArr); } else { emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent()); }*/ emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent()); } } final String attach = attachment; AndroidNativeUtil.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."), new IntentResultListener() { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (attach != null && attach.length() > 0 && attach.contains("tmp")) { FileSystemStorage.getInstance().delete(attach); } } }); }
From source file:com.zoffcc.applications.zanavi.Navit.java
void sendEmail(String recipient, String subject, String message) { try {//w w w . j av a2s . c o m final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient }); if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); startActivity(Intent.createChooser(emailIntent, Navit.get_text("Send feedback via email ..."))); } catch (ActivityNotFoundException e) { // cannot send email for some reason } }
From source file:com.zoffcc.applications.zanavi.Navit.java
void sendEmailWithAttachment(Context c, final String recipient, final String subject, final String message, final String full_file_name, final String full_file_name_suppl) { try {/*from ww w .j ava 2 s . c om*/ Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); ArrayList<Uri> uris = new ArrayList<>(); uris.add(Uri.parse("file://" + full_file_name)); try { if (new File(full_file_name_suppl).length() > 0) { uris.add(Uri.parse("file://" + full_file_name_suppl)); } } catch (Exception e) { e.printStackTrace(); } List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0); List<LabeledIntent> intents = new ArrayList<>(); if (resolveInfos.size() != 0) { for (ResolveInfo info : resolveInfos) { Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); System.out.println( "email:" + "comp=" + info.activityInfo.packageName + " " + info.activityInfo.name); intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name)); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { recipient }); if (subject != null) intent.putExtra(Intent.EXTRA_SUBJECT, subject); if (message != null) intent.putExtra(Intent.EXTRA_TEXT, message); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); intents.add(new LabeledIntent(intent, info.activityInfo.packageName, info.loadLabel(getPackageManager()), info.icon)); } Intent chooser = Intent.createChooser(intents.remove(intents.size() - 1), Navit.get_text("Send email with attachments")); chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new LabeledIntent[intents.size()])); startActivity(chooser); } else { System.out.println("email:" + "No Email App found"); new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found")) .setPositiveButton(Navit.get_text("Ok"), null).show(); } // final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null)); // if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient }); // if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); // if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); // if (full_file_name != null) // { // emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + full_file_name)); // //ArrayList<Uri> uris = new ArrayList<>(); // //uris.add(Uri.parse("file://" + full_file_name)); // //emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); //ArrayList<Uri> of attachment Uri's // } // // List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0); // if (resolveInfos.size() != 0) // { // String packageName = resolveInfos.get(0).activityInfo.packageName; // String name = resolveInfos.get(0).activityInfo.name; // // emailIntent.setAction(Intent.ACTION_SEND); // emailIntent.setComponent(new ComponentName(packageName, name)); // // System.out.println("email:" + "comp=" + packageName + " " + name); // // startActivity(emailIntent); // } // else // { // System.out.println("email:" + "No Email App found"); // new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found")).setPositiveButton(Navit.get_text("Ok"), null).show(); // } } catch (ActivityNotFoundException e) { // cannot send email for some reason } }