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:com.asksven.betterbatterystats.ShareDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction //ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light_Dialog); ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), BaseActivity.getTheme(getActivity())); AlertDialog.Builder builder = new AlertDialog.Builder(context); final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>(); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean saveAsText = sharedPrefs.getBoolean("save_as_text", true); boolean saveAsJson = sharedPrefs.getBoolean("save_as_json", false); boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false); boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false); final String m_refFromName = ""; final String m_refToName = ""; if (saveAsText) { selectedSaveActions.add(0);/*from ww w .j av a2 s . c om*/ } if (saveAsJson) { selectedSaveActions.add(1); } if (saveLogcat) { selectedSaveActions.add(2); } if (saveDmesg) { selectedSaveActions.add(3); } builder.setTitle("Title"); builder.setMultiChoiceItems(R.array.saveAsLabels, new boolean[] { saveAsText, saveAsJson, saveLogcat, saveDmesg }, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { // If the user checked the item, add it to the // selected items selectedSaveActions.add(which); } else if (selectedSaveActions.contains(which)) { // Else, if the item is already in the array, // remove it selectedSaveActions.remove(Integer.valueOf(which)); } } }) // Set the action buttons .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { ArrayList<Uri> attachements = new ArrayList<Uri>(); Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, getActivity()); Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, getActivity()); Reading reading = new Reading(getActivity(), myReferenceFrom, myReferenceTo); // save as text is selected if (selectedSaveActions.contains(0)) { attachements.add(reading.writeToFileText(getActivity())); } // save as JSON if selected if (selectedSaveActions.contains(1)) { attachements.add(reading.writeToFileJson(getActivity())); } // save logcat if selected if (selectedSaveActions.contains(2)) { attachements.add(StatsProvider.getInstance(getActivity()).writeLogcatToFile()); } // save dmesg if selected if (selectedSaveActions.contains(3)) { attachements.add(StatsProvider.getInstance(getActivity()).writeDmesgToFile()); } if (!attachements.isEmpty()) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements); shareIntent.setType("text/*"); startActivity(Intent.createChooser(shareIntent, "Share info to..")); } } }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, getActivity()); Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, getActivity()); Reading reading = new Reading(getActivity(), myReferenceFrom, myReferenceTo); // save as text is selected // save as text is selected if (selectedSaveActions.contains(0)) { reading.writeToFileText(getActivity()); } // save as JSON if selected if (selectedSaveActions.contains(1)) { reading.writeToFileJson(getActivity()); } // save logcat if selected if (selectedSaveActions.contains(2)) { StatsProvider.getInstance(getActivity()).writeLogcatToFile(); } // save dmesg if selected if (selectedSaveActions.contains(3)) { StatsProvider.getInstance(getActivity()).writeDmesgToFile(); } } }).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // do nothing } }); // Create the AlertDialog object and return it return builder.create(); }
From source file:com.cerema.cloud2.ui.activity.LogHistoryActivity.java
/** * Start activity for sending email with logs attached *///from ww w . j av a 2s . c o m private void sendMail() { // For the moment we need to consider the possibility that setup.xml // does not include the "mail_logger" entry. This block prevents that // compilation fails in this case. String emailAddress; try { Class<?> stringClass = R.string.class; Field mailLoggerField = stringClass.getField("mail_logger"); int emailAddressId = (Integer) mailLoggerField.get(null); emailAddress = getString(emailAddressId); } catch (Exception e) { emailAddress = ""; } ArrayList<Uri> uris = new ArrayList<Uri>(); // Convert from paths to Android friendly Parcelable Uri's for (String file : Log_OC.getLogFileNames()) { File logFile = new File(mLogPath, file); if (logFile.exists()) { uris.add(Uri.fromFile(logFile)); } } Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_EMAIL, emailAddress); String subject = String.format(getString(R.string.log_send_mail_subject), getString(R.string.app_name)); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType(MAIL_ATTACHMENT_TYPE); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(this, getString(R.string.log_send_no_mail_app), Toast.LENGTH_LONG).show(); Log_OC.i(TAG, "Could not find app for sending log history."); } }
From source file:es.danirod.rectball.android.AndroidSharing.java
/** * This method builds an Intent for sharing the screenshot with other apps * present in the mobile phone. The URI should point to the screenshot. * * @param uri URI that points to the screenshot to be saved * @param message message to be present in the screenshot * @return the Intent ready to be passed to the activity. *//*from ww w . java 2 s.c o m*/ private Intent shareScreenshotURI(Uri uri, CharSequence message) { Intent sharingIntent = new Intent(); sharingIntent.setAction(Intent.ACTION_SEND); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, message); sharingIntent.putExtra(Intent.EXTRA_TEXT, message); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); return sharingIntent; }
From source file:com.doplgangr.secrecy.views.FileViewer.java
void sendMultiple(final ArrayList<FilesListFragment.DecryptArgHolder> args) { new Thread(new Runnable() { @Override/* w w w . j a v a 2 s. co m*/ public void run() { ArrayList<Uri> uris = new ArrayList<Uri>(); Set<String> mimes = new HashSet<String>(); MimeTypeMap myMime = MimeTypeMap.getSingleton(); for (FilesListFragment.DecryptArgHolder arg : args) { File tempFile = getFile(arg.encryptedFile, arg.onFinish); //File specified is not invalid if (tempFile != null) { if (tempFile.getParentFile().equals(Storage.getTempFolder())) tempFile = new java.io.File(Storage.getTempFolder(), tempFile.getName()); uris.add(OurFileProvider.getUriForFile(context, OurFileProvider.FILE_PROVIDER_AUTHORITY, tempFile)); mimes.add(myMime.getMimeTypeFromExtension(arg.encryptedFile.getType())); } } if (uris.size() == 0 || mimes.size() == 0) return; Intent newIntent; if (uris.size() == 1) { newIntent = new Intent(Intent.ACTION_SEND); newIntent.putExtra(Intent.EXTRA_STREAM, uris.get(0)); } else { newIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); newIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } if (mimes.size() > 1) newIntent.setType("text/plain"); //Mixed filetypes else newIntent.setType(new ArrayList<String>(mimes).get(0)); newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent chooserIntent = generateCustomChooserIntent(newIntent, uris); try { startActivity(Intent.createChooser(chooserIntent, CustomApp.context.getString(R.string.Dialog__send_file))); FilesActivity.onPauseDecision.startActivity(); } catch (android.content.ActivityNotFoundException e) { Util.toast(context, CustomApp.context.getString(R.string.Error__no_activity_view), Toast.LENGTH_LONG); FilesActivity.onPauseDecision.finishActivity(); } } }).start(); }
From source file:com.synox.android.ui.activity.LogHistoryActivity.java
/** * Start activity for sending email with logs attached */// w w w .j a v a2 s. co m private void sendMail() { // For the moment we need to consider the possibility that setup.xml // does not include the "mail_logger" entry. This block prevents that // compilation fails in this case. String emailAddress; try { Class<?> stringClass = R.string.class; Field mailLoggerField = stringClass.getField("mail_logger"); int emailAddressId = (Integer) mailLoggerField.get(null); emailAddress = getString(emailAddressId); } catch (Exception e) { emailAddress = ""; } ArrayList<Uri> uris = new ArrayList<>(); // Convert from paths to Android friendly Parcelable Uri's for (String file : Log_OC.getLogFileNames()) { File logFile = new File(mLogPath, file); if (logFile.exists()) { uris.add(Uri.fromFile(logFile)); } } Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_EMAIL, emailAddress); String subject = String.format(getString(R.string.log_send_mail_subject), getString(R.string.app_name)); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType(MAIL_ATTACHMENT_TYPE); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(this, getString(R.string.log_send_no_mail_app), Toast.LENGTH_LONG).show(); Log_OC.i(TAG, "Could not find app for sending log history."); } }
From source file:fr.free.nrw.commons.settings.SettingsFragment.java
private void sendAppLogsViaEmail() { String appLogs = Utils.getAppLogs(); File appLogsFile = FileUtils.createAndGetAppLogsFile(appLogs); Context applicationContext = getActivity().getApplicationContext(); Uri appLogsFilePath = FileProvider.getUriForFile(getActivity(), applicationContext.getPackageName() + ".provider", appLogsFile); Intent feedbackIntent = new Intent(Intent.ACTION_SEND); feedbackIntent.setType("message/rfc822"); feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CommonsApplication.LOGS_PRIVATE_EMAIL }); feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, BuildConfig.VERSION_NAME)); feedbackIntent.putExtra(Intent.EXTRA_STREAM, appLogsFilePath); try {//from w w w . j ava 2s . co m startActivity(feedbackIntent); } catch (ActivityNotFoundException e) { Toast.makeText(getActivity(), R.string.no_email_client, Toast.LENGTH_SHORT).show(); } }
From source file:com.module.candychat.net.activity.PictureActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_share) { Handler uiHandler = new Handler(Looper.getMainLooper()); uiHandler.post(new Runnable() { @Override/*from ww w . j ava 2 s .c om*/ public void run() { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, getShareImageUri(mImageTitle, mImageUrl)); shareIntent.setType("image/jpg"); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(shareIntent, "Share...")); //ShareUtils.shareImage(getApplicationContext(), getShareImageUri(mImageTitle,mImageUrl), "Share..."); } }); //return true; } else if (id == R.id.action_save) { Handler uiHandler = new Handler(Looper.getMainLooper()); uiHandler.post(new Runnable() { @Override public void run() { saveImageToGallery(); } }); //return true; } else if (id == android.R.id.home) { finish(); } return super.onOptionsItemSelected(item); }
From source file:com.codebutler.farebot.fragments.CardsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { try {//from w ww . j ava 2 s .c om if (item.getItemId() == R.id.import_clipboard) { @SuppressWarnings("deprecation") ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Activity.CLIPBOARD_SERVICE); onCardsImported(ExportHelper.importCardsXml(getActivity(), clipboard.getText().toString())); return true; } else if (item.getItemId() == R.id.import_file) { Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory()); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.putExtra(Intent.EXTRA_STREAM, uri); i.setType("application/xml"); startActivityForResult(Intent.createChooser(i, "Select File"), REQUEST_SELECT_FILE); return true; } else if (item.getItemId() == R.id.import_sd) { String xml = FileUtils.readFileToString(new File(SD_EXPORT_PATH)); onCardsImported(ExportHelper.importCardsXml(getActivity(), xml)); return true; } else if (item.getItemId() == R.id.copy_xml) { @SuppressWarnings("deprecation") ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Activity.CLIPBOARD_SERVICE); clipboard.setText(ExportHelper.exportCardsXml(getActivity())); Toast.makeText(getActivity(), "Copied to clipboard.", 5).show(); return true; } else if (item.getItemId() == R.id.share_xml) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, ExportHelper.exportCardsXml(getActivity())); startActivity(intent); return true; } else if (item.getItemId() == R.id.save_xml) { String xml = ExportHelper.exportCardsXml(getActivity()); File file = new File(SD_EXPORT_PATH); FileUtils.writeStringToFile(file, xml, "UTF-8"); Toast.makeText(getActivity(), "Wrote FareBot-Export.xml to USB Storage.", 5).show(); return true; } } catch (Exception ex) { Utils.showError(getActivity(), ex); } return false; }
From source file:com.example.android.mmschallenge.MainActivity.java
/** * Sets the image Uri and creates implicit intent with ACTION_SEND * to launch an app to send the image./*from w ww. ja va 2 s .co m*/ */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); if (requestCode == IMAGE_PICK) { if (resultCode == RESULT_OK) { Log.d(TAG, getString(R.string.picture_chosen)); Uri mSelectedImage = imageReturnedIntent.getData(); Log.d(TAG, "onActivityResult: " + mSelectedImage.toString()); Intent smsIntent = new Intent(Intent.ACTION_SEND); smsIntent.putExtra(Intent.EXTRA_STREAM, mSelectedImage); smsIntent.setType("image/*"); if (smsIntent.resolveActivity(getPackageManager()) != null) { startActivity(smsIntent); } else { Log.d(TAG, "Can't resolve app for ACTION_SEND Intent."); } } } }
From source file:com.codebutler.farebot.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { try {//from www .jav a 2s.c om if (item.getItemId() == R.id.supported_cards) { startActivity(new Intent(this, SupportedCardsActivity.class)); return true; } else if (item.getItemId() == R.id.about) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://codebutler.github.com/farebot"))); return true; } else if (item.getItemId() == R.id.import_clipboard) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); onCardsImported(ExportHelper.importCardsXml(this, clipboard.getText().toString())); return true; } else if (item.getItemId() == R.id.import_file) { Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory()); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.putExtra(Intent.EXTRA_STREAM, uri); i.setType("application/xml"); startActivityForResult(Intent.createChooser(i, "Select File"), SELECT_FILE); return true; } else if (item.getItemId() == R.id.import_sd) { String xml = FileUtils.readFileToString(new File(SD_EXPORT_PATH)); onCardsImported(ExportHelper.importCardsXml(this, xml)); return true; } else if (item.getItemId() == R.id.copy_xml) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(ExportHelper.exportCardsXml(this)); Toast.makeText(this, "Copied to clipboard.", 5).show(); return true; } else if (item.getItemId() == R.id.share_xml) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, ExportHelper.exportCardsXml(this)); startActivity(intent); return true; } else if (item.getItemId() == R.id.save_xml) { String xml = ExportHelper.exportCardsXml(this); File file = new File(SD_EXPORT_PATH); FileUtils.writeStringToFile(file, xml, "UTF-8"); Toast.makeText(this, "Wrote FareBot-Export.xml to USB Storage.", 5).show(); return true; } else if (item.getItemId() == R.id.prefs) { startActivity(new Intent(this, FareBotPreferenceActivity.class)); } } catch (Exception ex) { Utils.showError(this, ex); } return false; }