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:free.yhc.netmbuddy.utils.Utils.java
public static void sendMail(Context context, String receiver, String subject, String text, File attachment) { if (!Utils.isNetworkAvailable()) return;/*from w w w. j a v a2 s . c om*/ Intent intent = new Intent(Intent.ACTION_SEND); if (null != receiver) intent.putExtra(Intent.EXTRA_EMAIL, new String[] { receiver }); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_SUBJECT, subject); if (null != attachment) intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment)); intent.setType("message/rfc822"); try { context.startActivity(intent); } catch (ActivityNotFoundException e) { UiUtils.showTextToast(context, R.string.msg_fail_find_app); } }
From source file:com.klinker.android.twitter.activities.compose.Compose.java
void handleSendImage(Intent intent) { Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); if (imageUri != null) { //String filePath = IOUtils.getPath(imageUri, context); try {/*w ww . j a va 2 s .c om*/ attachImage[imagesAttached].setImageBitmap(getThumbnail(imageUri)); attachImage[imagesAttached].setVisibility(View.VISIBLE); attachedUri[imagesAttached] = imageUri.toString(); imagesAttached++; //numberAttached.setText(imagesAttached + " " + getResources().getString(R.string.attached_images)); //numberAttached.setVisibility(View.VISIBLE); } catch (FileNotFoundException e) { Toast.makeText(context, getResources().getString(R.string.error), Toast.LENGTH_SHORT); //numberAttached.setText(""); //numberAttached.setVisibility(View.GONE); } catch (IOException e) { Toast.makeText(context, getResources().getString(R.string.error), Toast.LENGTH_SHORT); //numberAttached.setText(""); //numberAttached.setVisibility(View.GONE); } } }
From source file:com.daiv.android.twitter.ui.compose.Compose.java
void handleSendImage(Intent intent) { Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (imageUri != null) { //String filePath = IOUtils.getPath(imageUri, context); try {/*from ww w . j a va 2s . c o m*/ attachImage[imagesAttached].setImageBitmap(getThumbnail(imageUri)); attachImage[imagesAttached].setVisibility(View.VISIBLE); attachedUri[imagesAttached] = imageUri.toString(); imagesAttached++; //numberAttached.setText(imagesAttached + " " + getResources().getString(R.string.attached_images)); //numberAttached.setVisibility(View.VISIBLE); } catch (FileNotFoundException e) { Toast.makeText(context, getResources().getString(R.string.error), Toast.LENGTH_SHORT); //numberAttached.setText(""); //numberAttached.setVisibility(View.GONE); } catch (IOException e) { Toast.makeText(context, getResources().getString(R.string.error), Toast.LENGTH_SHORT); //numberAttached.setText(""); //numberAttached.setVisibility(View.GONE); } } }
From source file:net.gsantner.opoc.util.ShareUtil.java
/** * Try to force extract a absolute filepath from an intent * * @param receivingIntent The intent from {@link Activity#getIntent()} * @return A file or null if extraction did not succeed */// www . j av a 2s .c o m public File extractFileFromIntent(Intent receivingIntent) { String action = receivingIntent.getAction(); String type = receivingIntent.getType(); File tmpf; String tmps; String fileStr; if ((Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) || Intent.ACTION_SEND.equals(action)) { // Markor, S.M.T FileManager if (receivingIntent.hasExtra((tmps = EXTRA_FILEPATH))) { return new File(receivingIntent.getStringExtra(tmps)); } // Analyze data/Uri Uri fileUri = receivingIntent.getData(); if (fileUri != null && (fileStr = fileUri.toString()) != null) { // Uri contains file if (fileStr.startsWith("file://")) { return new File(fileUri.getPath()); } if (fileStr.startsWith((tmps = "content://"))) { fileStr = fileStr.substring(tmps.length()); String fileProvider = fileStr.substring(0, fileStr.indexOf("/")); fileStr = fileStr.substring(fileProvider.length() + 1); // Some file managers dont add leading slash if (fileStr.startsWith("storage/")) { fileStr = "/" + fileStr; } // Some do add some custom prefix for (String prefix : new String[] { "file", "document", "root_files", "name" }) { if (fileStr.startsWith(prefix)) { fileStr = fileStr.substring(prefix.length()); } } // Next/OwnCloud Fileprovider for (String fp : new String[] { "org.nextcloud.files", "org.nextcloud.beta.files", "org.owncloud.files" }) { if (fileProvider.equals(fp) && fileStr.startsWith(tmps = "external_files/")) { return new File(Uri.decode("/storage/" + fileStr.substring(tmps.length()))); } } // AOSP File Manager/Documents if (fileProvider.equals("com.android.externalstorage.documents") && fileStr.startsWith(tmps = "/primary%3A")) { return new File(Uri.decode(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileStr.substring(tmps.length()))); } // Mi File Explorer if (fileProvider.equals("com.mi.android.globalFileexplorer.myprovider") && fileStr.startsWith(tmps = "external_files")) { return new File(Uri.decode(Environment.getExternalStorageDirectory().getAbsolutePath() + fileStr.substring(tmps.length()))); } // URI Encoded paths with full path after content://package/ if (fileStr.startsWith("/") || fileStr.startsWith("%2F")) { tmpf = new File(Uri.decode(fileStr)); if (tmpf.exists()) { return tmpf; } else if ((tmpf = new File(fileStr)).exists()) { return tmpf; } } } } fileUri = receivingIntent.getParcelableExtra(Intent.EXTRA_STREAM); if (fileUri != null && !TextUtils.isEmpty(tmps = fileUri.getPath()) && tmps.startsWith("/") && (tmpf = new File(tmps)).exists()) { return tmpf; } } return null; }
From source file:nya.miku.wishmaster.ui.GalleryActivity.java
private void share() { GalleryItemViewTag tag = getCurrentTag(); if (tag == null) return;//from w ww. j a v a 2 s. c o m Intent shareIntent = new Intent(Intent.ACTION_SEND); String extension = Attachments.getAttachmentExtention(tag.attachmentModel); switch (tag.attachmentModel.type) { case AttachmentModel.TYPE_IMAGE_GIF: shareIntent.setType("image/gif"); break; case AttachmentModel.TYPE_IMAGE_STATIC: if (extension.equalsIgnoreCase(".png")) { shareIntent.setType("image/png"); } else if (extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".jpg")) { shareIntent.setType("image/jpeg"); } else { shareIntent.setType("image/*"); } break; case AttachmentModel.TYPE_VIDEO: if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("video/mp4"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("video/webm"); } else if (extension.equalsIgnoreCase(".avi")) { shareIntent.setType("video/avi"); } else if (extension.equalsIgnoreCase(".mov")) { shareIntent.setType("video/quicktime"); } else if (extension.equalsIgnoreCase(".mkv")) { shareIntent.setType("video/x-matroska"); } else if (extension.equalsIgnoreCase(".flv")) { shareIntent.setType("video/x-flv"); } else if (extension.equalsIgnoreCase(".wmv")) { shareIntent.setType("video/x-ms-wmv"); } else { shareIntent.setType("video/*"); } break; case AttachmentModel.TYPE_AUDIO: if (extension.equalsIgnoreCase(".mp3")) { shareIntent.setType("audio/mpeg"); } else if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("audio/mp4"); } else if (extension.equalsIgnoreCase(".ogg")) { shareIntent.setType("audio/ogg"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("audio/webm"); } else if (extension.equalsIgnoreCase(".flac")) { shareIntent.setType("audio/flac"); } else if (extension.equalsIgnoreCase(".wav")) { shareIntent.setType("audio/vnd.wave"); } else { shareIntent.setType("audio/*"); } break; case AttachmentModel.TYPE_OTHER_FILE: shareIntent.setType("application/octet-stream"); break; } Logger.d(TAG, shareIntent.getType()); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tag.file)); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_via))); }
From source file:com.visva.voicerecorder.utils.Utils.java
public static void shareAllRecordingSessionInfoAction(Context context, RecordingSession session) { File file = new File(session.fileName); if (!file.exists()) { AIOLog.e(MyCallRecorderConstant.TAG, "file not found"); }/*w ww . j a v a 2 s .c om*/ Uri uri = Uri.fromFile(file); String displayName = session.phoneName; Resources res = context.getResources(); StringBuilder builder = new StringBuilder(); if (!StringUtility.isEmpty(displayName)) builder.append(res.getString(R.string.name)).append(displayName + "\n"); builder.append(res.getString(R.string.phone_no)).append(session.phoneNo); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, res.getString(R.string.share_record)); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, builder.toString()); shareIntent.setType("*/*"); context.startActivity(Intent.createChooser(shareIntent, "Share via")); }
From source file:com.mbientlab.metawear.app.LoggingFragment.java
private void startEmailIntent() { mwMnger.getCurrentController().removeModuleCallback(sensors[sensorIndex]); ArrayList<Uri> fileUris = new ArrayList<>(); try {// w ww . j a v a2 s .c om for (File it : sensors[sensorIndex].saveDataToFile()) { fileUris.add( FileProvider.getUriForFile(getActivity(), "com.mbientlab.metawear.app.fileprovider", it)); } Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, String.format(Locale.US, "Logged %s data - %tY-%<tm-%<tdT%<tH-%<tM-%<tS", sensors[sensorIndex].toString(), Calendar.getInstance().getTime())); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris); startActivity(Intent.createChooser(intent, "Send email...")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:net.movelab.cmlibrary.MapMyData.java
private void shareMap(Context context) { try {// w w w . j a v a2 s . co m File root = Environment.getExternalStorageDirectory(); File directory = new File(root, "SpaceMapper"); directory.mkdirs(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); Date date = new Date(); String stringDate = dateFormat.format(date); String filename = getResources().getString(R.string.filenameprefix_map) + stringDate + ".jpg"; if (directory.canWrite()) { File f = new File(directory, filename); FileOutputStream out = new FileOutputStream(f); Bitmap bmp = getMapImage(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, out); out.close(); Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/jpeg"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); // add the message share.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getText(R.string.made_with_SM) + ": https://play.google.com/store/apps/details?id=" + getResources().getString(R.string.package_name)); startActivity(Intent.createChooser(share, getResources().getText(R.string.share_with))); } else { Util.toast(context, getResources().getString(R.string.data_SD_unavailable)); } } catch (IOException e) { Util.toast(context, getResources().getString(R.string.data_SD_error)); } }
From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java
private void share() { GalleryItemViewTag tag = getCurrentTag(); if (tag == null) return;//w ww .j ava 2 s .co m Intent shareIntent = new Intent(Intent.ACTION_SEND); String extension = Attachments.getAttachmentExtention(tag.attachmentModel); switch (tag.attachmentModel.type) { case AttachmentModel.TYPE_IMAGE_GIF: shareIntent.setType("image/gif"); break; case AttachmentModel.TYPE_IMAGE_SVG: shareIntent.setType("image/svg+xml"); break; case AttachmentModel.TYPE_IMAGE_STATIC: if (extension.equalsIgnoreCase(".png")) { shareIntent.setType("image/png"); } else if (extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".jpg")) { shareIntent.setType("image/jpeg"); } else { shareIntent.setType("image/*"); } break; case AttachmentModel.TYPE_VIDEO: if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("video/mp4"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("video/webm"); } else if (extension.equalsIgnoreCase(".avi")) { shareIntent.setType("video/avi"); } else if (extension.equalsIgnoreCase(".mov")) { shareIntent.setType("video/quicktime"); } else if (extension.equalsIgnoreCase(".mkv")) { shareIntent.setType("video/x-matroska"); } else if (extension.equalsIgnoreCase(".flv")) { shareIntent.setType("video/x-flv"); } else if (extension.equalsIgnoreCase(".wmv")) { shareIntent.setType("video/x-ms-wmv"); } else { shareIntent.setType("video/*"); } break; case AttachmentModel.TYPE_AUDIO: if (extension.equalsIgnoreCase(".mp3")) { shareIntent.setType("audio/mpeg"); } else if (extension.equalsIgnoreCase(".mp4")) { shareIntent.setType("audio/mp4"); } else if (extension.equalsIgnoreCase(".ogg")) { shareIntent.setType("audio/ogg"); } else if (extension.equalsIgnoreCase(".webm")) { shareIntent.setType("audio/webm"); } else if (extension.equalsIgnoreCase(".flac")) { shareIntent.setType("audio/flac"); } else if (extension.equalsIgnoreCase(".wav")) { shareIntent.setType("audio/vnd.wave"); } else { shareIntent.setType("audio/*"); } break; case AttachmentModel.TYPE_OTHER_FILE: shareIntent.setType("application/octet-stream"); break; } Logger.d(TAG, shareIntent.getType()); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tag.file)); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_via))); }
From source file:com.visva.voicerecorder.utils.Utils.java
public static void shareMultiFileByShareActionMode(Context context, ArrayList<RecordingSession> selectedList) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files."); intent.setType("image/jpeg"); /* This example is sharing jpeg images. */ ArrayList<Uri> files = new ArrayList<Uri>(); for (RecordingSession recordingSession : selectedList /* List of the files you want to send */) { File file = new File(recordingSession.fileName); Uri uri = Uri.fromFile(file);/* w w w .ja va2 s .c o m*/ files.add(uri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); context.startActivity(intent); }