List of usage examples for android.content Intent EXTRA_STREAM
String EXTRA_STREAM
To view the source code for android.content Intent EXTRA_STREAM.
Click Source Link
From source file:im.neon.activity.VectorRoomActivity.java
@SuppressLint("NewApi") /**//from w ww . j av a 2 s . co m * Send the medias defined in the intent. * They are listed, checked and sent when it is possible. */ private void sendMediasIntent(final Intent intent) { // sanity check if ((null == intent) && (null == mLatestTakePictureCameraUri)) { return; } ArrayList<SharedDataItem> sharedDataItems = new ArrayList<>(); if (null != intent) { sharedDataItems = new ArrayList<>(SharedDataItem.listSharedDataItems(intent)); } else if (null != mLatestTakePictureCameraUri) { sharedDataItems.add(new SharedDataItem(Uri.parse(mLatestTakePictureCameraUri))); mLatestTakePictureCameraUri = null; } // check the extras if (0 == sharedDataItems.size()) { Bundle bundle = intent.getExtras(); // sanity checks if (null != bundle) { bundle.setClassLoader(SharedDataItem.class.getClassLoader()); if (bundle.containsKey(Intent.EXTRA_STREAM)) { try { Object streamUri = bundle.get(Intent.EXTRA_STREAM); if (streamUri instanceof Uri) { sharedDataItems.add(new SharedDataItem((Uri) streamUri)); } else if (streamUri instanceof List) { List<Object> streams = (List<Object>) streamUri; for (Object object : streams) { if (object instanceof Uri) { sharedDataItems.add(new SharedDataItem((Uri) object)); } else if (object instanceof SharedDataItem) { sharedDataItems.add((SharedDataItem) object); } } } } catch (Exception e) { Log.e(LOG_TAG, "fail to extract the extra stream"); } } else if (bundle.containsKey(Intent.EXTRA_TEXT)) { mEditText.setText(mEditText.getText() + bundle.getString(Intent.EXTRA_TEXT)); mEditText.post(new Runnable() { @Override public void run() { mEditText.setSelection(mEditText.getText().length()); } }); } } } if (0 != sharedDataItems.size()) { mVectorRoomMediasSender.sendMedias(sharedDataItems); } }
From source file:com.ywesee.amiko.MainActivity.java
/** * Starts email activity/*from ww w .j av a2 s . co m*/ * @param context * @param attachment */ public void startEmailActivity(Context context, Uri attachment, String emailAddr, String subject) { Intent sendEmailIntent = new Intent(Intent.ACTION_SEND); sendEmailIntent.setType("message/rfc822"); sendEmailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { emailAddr }); sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); sendEmailIntent.putExtra(Intent.EXTRA_TEXT, "AmiKo for Android\r\n\nGet it now: https://play.google.com/store/apps/details?id=com.ywesee.amiko.de\r\n\nEnjoy!"); sendEmailIntent.putExtra(Intent.EXTRA_STREAM, attachment); context.startActivity(Intent.createChooser(sendEmailIntent, "Send email")); }
From source file:im.vector.activity.RoomActivity.java
@SuppressLint("NewApi") private void sendMediasIntent(final Intent data) { // sanity check if ((null == data) && (null == mLatestTakePictureCameraUri)) { return;// w w w. j a v a2 s. com } ArrayList<Uri> uris = new ArrayList<Uri>(); if (null != data) { ClipData clipData = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { clipData = data.getClipData(); } // multiple data if (null != clipData) { int count = clipData.getItemCount(); for (int i = 0; i < count; i++) { ClipData.Item item = clipData.getItemAt(i); Uri uri = item.getUri(); if (null != uri) { uris.add(uri); } } } else if (null != data.getData()) { uris.add(data.getData()); } } else if (null != mLatestTakePictureCameraUri) { uris.add(Uri.parse(mLatestTakePictureCameraUri)); mLatestTakePictureCameraUri = null; } // check the extras if (0 == uris.size()) { Bundle bundle = data.getExtras(); // sanity checks if (null != bundle) { if (bundle.containsKey(Intent.EXTRA_STREAM)) { Object streamUri = bundle.get(Intent.EXTRA_STREAM); if (streamUri instanceof Uri) { uris.add((Uri) streamUri); } } else if (bundle.containsKey(Intent.EXTRA_TEXT)) { this.sendMessage(bundle.getString(Intent.EXTRA_TEXT)); } } else { uris.add(mLatestTakePictureCameraUri == null ? null : Uri.parse(mLatestTakePictureCameraUri)); mLatestTakePictureCameraUri = null; } } if (0 != uris.size()) { sendMedias(uris); } }
From source file:com.ichi2.anki.DeckPicker.java
public void emailFile(String path) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_SUBJECT, "AnkiDroid Apkg"); File attachment = new File(path); if (attachment.exists()) { Uri uri = Uri.fromFile(attachment); intent.putExtra(Intent.EXTRA_STREAM, uri); }//from ww w .j a v a 2 s . c om try { startActivityWithoutAnimation(intent); } catch (ActivityNotFoundException e) { Themes.showThemedToast(this, getResources().getString(R.string.no_email_client), false); } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Allows to create a share intent and it can be launched. * /*from w ww .j av a2 s . c o m*/ * @param context * @param type Mime type. * @param nameApp You can filter the application you want to share with. Use "wha", "twitt", etc. * @param title The title of the share.Take in account that sometimes is not possible to add the title. * @param data The data, can be a file or a text. * @param isBinaryData If the share has a data file, set to TRUE otherwise FALSE. */ @SuppressLint("DefaultLocale") public static Intent share_newSharingIntent(Context context, String type, String nameApp, String title, String data, boolean isBinaryData, boolean launch) { Intent res = null; Intent share = new Intent(Intent.ACTION_SEND); share.setType(type); List<Intent> targetedShareIntents = new ArrayList<Intent>(); List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(share, 0); if (!resInfo.isEmpty()) { for (ResolveInfo info : resInfo) { Intent targetedShare = new Intent(Intent.ACTION_SEND); targetedShare.setType(type); if (title != null) { targetedShare.putExtra(Intent.EXTRA_SUBJECT, title); targetedShare.putExtra(Intent.EXTRA_TITLE, title); if (data != null && !isBinaryData) { targetedShare.putExtra(Intent.EXTRA_TEXT, data); } } if (data != null && isBinaryData) { targetedShare.putExtra(Intent.EXTRA_TEXT, title); targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(data))); } if (nameApp != null) { if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) { targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } else { targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); res = chooserIntent; if (launch) { context.startActivity(chooserIntent); } } return res; }
From source file:com.android.mail.compose.ComposeActivity.java
private void initAttachmentsFromIntent(Intent intent) { Bundle extras = intent.getExtras();// w w w . java 2 s .c om if (extras == null) { extras = Bundle.EMPTY; } final String action = intent.getAction(); if (!mAttachmentsChanged) { long totalSize = 0; if (extras.containsKey(EXTRA_ATTACHMENTS)) { final String[] uris = (String[]) extras.getSerializable(EXTRA_ATTACHMENTS); final ArrayList<Uri> parsedUris = Lists.newArrayListWithCapacity(uris.length); for (String uri : uris) { parsedUris.add(Uri.parse(uri)); } totalSize += handleAttachmentUrisFromIntent(parsedUris); } if (extras.containsKey(Intent.EXTRA_STREAM)) { if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM); totalSize += handleAttachmentUrisFromIntent(uris); } else { final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM); final ArrayList<Uri> uris = Lists.newArrayList(uri); totalSize += handleAttachmentUrisFromIntent(uris); } } if (totalSize > 0) { mAttachmentsChanged = true; updateSaveUi(); Analytics.getInstance().sendEvent("send_intent_with_attachments", Integer.toString(getAttachments().size()), null, totalSize); } } }
From source file:com.jtschohl.androidfirewall.MainActivity.java
/** * Email error reports/*from w w w.j ava 2 s.c o m*/ */ 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.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.ja v 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();/*from ww w . j a v a 2s . c o m*/ 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; }