List of usage examples for android.content Intent ACTION_SEND
String ACTION_SEND
To view the source code for android.content Intent ACTION_SEND.
Click Source Link
From source file:com.android.mail.compose.ComposeActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { final boolean superCreated = super.onCreateOptionsMenu(menu); // Don't render any menu items when there are no accounts. if (mAccounts == null || mAccounts.length == 0) { return superCreated; }//ww w . j a v a 2s . c om MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.compose_menu, menu); /* * Start save in the correct enabled state. * 1) If a user launches compose from within gmail, save is disabled * until they add something, at which point, save is enabled, auto save * on exit; if the user empties everything, save is disabled, exiting does not * auto-save * 2) if a user replies/ reply all/ forwards from within gmail, save is * disabled until they change something, at which point, save is * enabled, auto save on exit; if the user empties everything, save is * disabled, exiting does not auto-save. * 3) If a user launches compose from another application and something * gets populated (attachments, recipients, body, subject, etc), save is * enabled, auto save on exit; if the user empties everything, save is * disabled, exiting does not auto-save */ mSave = menu.findItem(R.id.save); String action = getIntent() != null ? getIntent().getAction() : null; enableSave(mInnerSavedState != null ? mInnerSavedState.getBoolean(EXTRA_SAVE_ENABLED) : (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action) || Intent.ACTION_SENDTO.equals(action) || isDraftDirty())); final MenuItem helpItem = menu.findItem(R.id.help_info_menu_item); final MenuItem sendFeedbackItem = menu.findItem(R.id.feedback_menu_item); final MenuItem attachFromServiceItem = menu.findItem(R.id.attach_from_service_stub1); if (helpItem != null) { helpItem.setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT)); } if (sendFeedbackItem != null) { sendFeedbackItem .setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK)); } if (attachFromServiceItem != null) { attachFromServiceItem.setVisible(shouldEnableAttachFromServiceMenu(mAccount)); } // Show attach picture on pre-K devices. menu.findItem(R.id.add_photo_attachment).setVisible(!Utils.isRunningKitkatOrLater()); return true; }
From source file:com.android.gallery3d.app.PhotoPage.java
private static Intent createShareIntent(Uri contentUri, int type) { return new Intent(Intent.ACTION_SEND).setType(MenuExecutor.getMimeType(type)) .putExtra(Intent.EXTRA_STREAM, contentUri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); }
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
private void shareContact() { final String lookupKey = mContactData.getLookupKey(); final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(Contacts.CONTENT_VCARD_TYPE); intent.putExtra(Intent.EXTRA_STREAM, shareUri); // Launch chooser to share contact via final CharSequence chooseTitle = getText(R.string.share_via); final Intent chooseIntent = Intent.createChooser(intent, chooseTitle); try {/*from www .j av a 2s . c o m*/ mHasIntentLaunched = true; ImplicitIntentsUtil.startActivityOutsideApp(this, chooseIntent); } catch (final ActivityNotFoundException ex) { Toast.makeText(this, R.string.share_error, Toast.LENGTH_SHORT).show(); } }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private boolean handleSendIntent() { Intent intent = getIntent();/* w w w.j a v a 2s . com*/ Bundle extras = intent.getExtras(); if (extras == null) { return false; } final String mimeType = intent.getType(); String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { if (extras.containsKey(Intent.EXTRA_STREAM)) { final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); getAsyncDialog().runAsync(new Runnable() { @Override public void run() { addAttachment(mimeType, uri, false); } }, null, R.string.adding_attachments_title); return true; } else if (extras.containsKey(Intent.EXTRA_TEXT)) { mWorkingMessage.setText(extras.getString(Intent.EXTRA_TEXT)); return true; } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && extras.containsKey(Intent.EXTRA_STREAM)) { SlideshowModel slideShow = mWorkingMessage.getSlideshow(); final ArrayList<Parcelable> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM); int currentSlideCount = slideShow != null ? slideShow.size() : 0; int importCount = uris.size(); if (importCount + currentSlideCount > SlideshowEditor.MAX_SLIDE_NUM) { importCount = Math.min(SlideshowEditor.MAX_SLIDE_NUM - currentSlideCount, importCount); Toast.makeText(ComposeMessageActivity.this, getString(R.string.too_many_attachments, SlideshowEditor.MAX_SLIDE_NUM, importCount), Toast.LENGTH_LONG).show(); } // Attach all the pictures/videos asynchronously off of the UI thread. // Show a progress dialog if adding all the slides hasn't finished // within half a second. final int numberToImport = importCount; getAsyncDialog().runAsync(new Runnable() { @Override public void run() { for (int i = 0; i < numberToImport; i++) { Parcelable uri = uris.get(i); addAttachment(mimeType, (Uri) uri, true); } } }, null, R.string.adding_attachments_title); return true; } return false; }
From source file:org.getlantern.firetweet.util.Utils.java
public static void startStatusShareChooser(final Context context, final ParcelableStatus status) { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); final String name = status.user_name, screenName = status.user_screen_name; final String timeString = formatToLongTimeString(context, status.timestamp); final String subject = context.getString(R.string.status_share_subject_format_with_time, name, screenName, timeString);//from w ww . j a v a 2s . c om intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, status.text_plain); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); context.startActivity(Intent.createChooser(intent, context.getString(R.string.share))); }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc/*from w w w . j av a 2 s .c o m*/ */ 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.codename1.impl.android.AndroidImplementation.java
@Override public void share(String text, String image, String mimeType, Rectangle sourceRect) { /*if(!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to perform share")){ return;//w w w .jav a2 s . com }*/ Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); if (image == null) { shareIntent.setType("text/plain"); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text); } else { shareIntent.setType(mimeType); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fixAttachmentPath(image))); shareIntent.putExtra(Intent.EXTRA_TEXT, text); } getContext().startActivity(Intent.createChooser(shareIntent, "Share with...")); }