/** * Uses the ShareCompat Intent builder to create our Forecast intent for sharing. All we need * to do is set the type, text and the NEW_DOCUMENT flag so it treats our share as a new task. * See: http://developer.android.com/guide/components/tasks-and-back-stack.html for more info. * * @return the Intent to use to share our weather forecast */ private Intent createShareForecastIntent() { Intent shareIntent = ShareCompat.IntentBuilder.from(this) .setType("text/plain") .setText(mForecastSummary + FORECAST_SHARE_HASHTAG) .getIntent(); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); return shareIntent; } }
+ Utils.getAppShareUri().toString(); ShareCompat.IntentBuilder .from(this) .setText(shareText) .setType("text/plain") .setChooserTitle("Share FireFiles") .startChooser(); AnalyticsManager.logEvent("app_share"); break;
/** * Set an HTML string to be sent as part of the share. * If {@link Intent#EXTRA_TEXT EXTRA_TEXT} has not already been supplied, * a styled version of the supplied HTML text will be added as EXTRA_TEXT as * parsed by {@link android.text.Html#fromHtml(String) Html.fromHtml}. * * @param htmlText A string containing HTML markup as a richer version of the text * provided by EXTRA_TEXT. * @return This IntentBuilder for method chaining * @see #setText(CharSequence) */ public IntentBuilder setHtmlText(String htmlText) { mIntent.putExtra(IntentCompat.EXTRA_HTML_TEXT, htmlText); if (!mIntent.hasExtra(Intent.EXTRA_TEXT)) { // Supply a default if EXTRA_TEXT isn't set setText(Html.fromHtml(htmlText)); } return this; }
/** * Handles the onClick for the "Share This Text" button. The * implicit intent here is created by the {@link ShareCompat.IntentBuilder} * class. An app chooser appears with the available options for sharing. * * ShareCompat.IntentBuilder is from the v4 Support Library. * * @param view The view (Button) that was clicked. */ public void shareText(View view) { String txt = mShareTextEditText.getText().toString(); String mimeType = "text/plain"; ShareCompat.IntentBuilder .from(this) .setType(mimeType) .setChooserTitle(R.string.share_text_with) .setText(txt) .startChooser(); } }
/** * Creates an intent to prompt the user for sharing text. * * @param title The name of the text being stored. * @param url The url to be shared. * @param activity The current activity. */ public static Intent shareText(String title, String url, Activity activity) { return ShareCompat.IntentBuilder.from(activity) .setSubject(title) .setText(url) .setStream(Uri.parse(url)) .setType(TEXT_PLAIN_MIME) .setChooserTitle(R.string.share) .getIntent(); }
/** * Uses the ShareCompat Intent builder to create our Forecast intent for sharing. All we need * to do is set the type, text and the NEW_DOCUMENT flag so it treats our share as a new task. * See: http://developer.android.com/guide/components/tasks-and-back-stack.html for more info. * * @return the Intent to use to share our weather forecast */ private Intent createShareForecastIntent() { Intent shareIntent = ShareCompat.IntentBuilder.from(this) .setType("text/plain") .setText(mForecastSummary + FORECAST_SHARE_HASHTAG) .getIntent(); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); return shareIntent; }
private void shareText (String text) { // COMPLETED (2) Create a String variable called mimeType and set it to "text/plain" String mimeType = "text/plain"; // COMPLETED (3) Create a title for the chooser window that will pop up String title = "Share with:"; // COMPLETED (4) Use ShareCompat.IntentBuilder to build the Intent and start the chooser ShareCompat.IntentBuilder .from(this) .setType(mimeType) .setChooserTitle(title) .setText(text) .startChooser(); } }
public void sharePhoto() { Uri uri = albumItem.getUri(this); Intent shareIntent = ShareCompat.IntentBuilder.from(this) .addStream(uri) .setType(MediaType.getMimeType(this, uri)) .getIntent(); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String title = getString(R.string.share_item, albumItem.getType(this)); if (shareIntent.resolveActivity(getPackageManager()) != null) { startActivity(Intent.createChooser(shareIntent, title)); } else { String error = getString(R.string.share_error, albumItem.getType(this)); Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); } }
/** * Uses the ShareCompat Intent builder to create our Forecast intent for sharing. We set the * type of content that we are sharing (just regular text), the text itself, and we return the * newly created Intent. * * @return The Intent to use to start our share. */ private Intent createShareForecastIntent() { Intent shareIntent = ShareCompat.IntentBuilder.from(this) .setType("text/plain") .setText(mForecast + FORECAST_SHARE_HASHTAG) .getIntent(); return shareIntent; }
private void combineArrayExtra(String extra, String[] add) { // Add any items still pending Intent intent = getIntent(); String[] old = intent.getStringArrayExtra(extra); int oldLength = old != null ? old.length : 0; String[] result = new String[oldLength + add.length]; if (old != null) System.arraycopy(old, 0, result, 0, oldLength); System.arraycopy(add, 0, result, oldLength, add.length); intent.putExtra(extra, result); }
/** * Create an Intent that will launch the standard Android activity chooser, * allowing the user to pick what activity/app on the system should handle * the share. * * @return A chooser Intent for the currently configured sharing action */ public Intent createChooserIntent() { return Intent.createChooser(getIntent(), mChooserTitle); }
/** * Set the title that will be used for the activity chooser for this share. * * @param resId Resource ID of the title string to use * @return This IntentBuilder for method chaining */ public IntentBuilder setChooserTitle(@StringRes int resId) { return setChooserTitle(mActivity.getText(resId)); }
public void configureMenuItem(MenuItem item, IntentBuilder shareIntent) { ShareCompatICS.configureMenuItem(item, shareIntent.getActivity(), shareIntent.getIntent()); if (shouldAddChooserIntent(item)) { item.setIntent(shareIntent.createChooserIntent()); } }
public static void sendMail(Activity activity, ReportMail reportMail, Uri fileUri) { Intent intent = ShareCompat.IntentBuilder.from(activity) .addEmailTo(reportMail.getEmail()) .setSubject(reportMail.getSubject()) .setText(reportMail.getBody()) .setType("text/plain") .setStream(fileUri) .getIntent() .addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); activity.startActivity(intent); }
private void combineArrayExtra(String extra, String[] add) { // Add any items still pending Intent intent = getIntent(); String[] old = intent.getStringArrayExtra(extra); int oldLength = old != null ? old.length : 0; String[] result = new String[oldLength + add.length]; if (old != null) System.arraycopy(old, 0, result, 0, oldLength); System.arraycopy(add, 0, result, oldLength, add.length); intent.putExtra(extra, result); }
/** * Create an Intent that will launch the standard Android activity chooser, * allowing the user to pick what activity/app on the system should handle * the share. * * @return A chooser Intent for the currently configured sharing action */ public Intent createChooserIntent() { return Intent.createChooser(getIntent(), mChooserTitle); }
public void configureMenuItem(MenuItem item, IntentBuilder shareIntent) { ShareCompatICS.configureMenuItem(item, shareIntent.getActivity(), shareIntent.getIntent()); } }
public static void sharePlainText(Activity activity, String textToShare) { ShareCompat.IntentBuilder .from(activity) .setText(textToShare) .setType("text/plain") .setChooserTitle(activity.getString(R.string.share_using)) .startChooser(); }