Example usage for android.content Intent ACTION_SEND

List of usage examples for android.content Intent ACTION_SEND

Introduction

In this page you can find the example usage for android.content Intent ACTION_SEND.

Prototype

String ACTION_SEND

To view the source code for android.content Intent ACTION_SEND.

Click Source Link

Document

Activity Action: Deliver some data to someone else.

Usage

From source file:com.google.android.apps.muzei.featuredart.FeaturedArtSource.java

@Override
protected void onCustomCommand(int id) {
    super.onCustomCommand(id);
    if (COMMAND_ID_SHARE == id) {
        Artwork currentArtwork = getCurrentArtwork();
        if (currentArtwork == null) {
            LOGW(TAG, "No current artwork, can't share.");
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override//ww w.j  ava2  s .  co m
                public void run() {
                    Toast.makeText(FeaturedArtSource.this,
                            R.string.featuredart_source_error_no_artwork_to_share, Toast.LENGTH_SHORT).show();
                }
            });
            return;
        }

        String detailUrl = ("initial".equals(currentArtwork.getToken()))
                ? "http://www.wikipaintings.org/en/vincent-van-gogh/the-starry-night-1889"
                : currentArtwork.getViewIntent().getDataString();
        String artist = currentArtwork.getByline().replaceFirst("\\.\\s*($|\\n).*", "").trim();

        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "My Android wallpaper today is '"
                + currentArtwork.getTitle().trim() + "' by " + artist + ". #MuzeiFeaturedArt\n\n" + detailUrl);
        shareIntent = Intent.createChooser(shareIntent, "Share artwork");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(shareIntent);

    } else if (COMMAND_ID_DEBUG_INFO == id) {
        long nextUpdateTimeMillis = getSharedPreferences().getLong("scheduled_update_time_millis", 0);
        final String nextUpdateTime;
        if (nextUpdateTimeMillis > 0) {
            Date d = new Date(nextUpdateTimeMillis);
            nextUpdateTime = SimpleDateFormat.getDateTimeInstance().format(d);
        } else {
            nextUpdateTime = "None";
        }

        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(FeaturedArtSource.this, "Next update time: " + nextUpdateTime, Toast.LENGTH_LONG)
                        .show();
            }
        });
    }
}

From source file:com.cairoconfessions.MainActivity.java

public void sendShare(View view) {
    Intent sendIntent = new Intent();
    String shareMessage = ((TextView) ((LinearLayout) view.getParent().getParent())
            .findViewById(R.id.text_main)).getText().toString();
    sendIntent.setAction(Intent.ACTION_SEND);
    shareMessage = "I would like to share this confession with you:\n\"" + shareMessage + '"';
    sendIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
    sendIntent.setType("text/plain");
    startActivity(sendIntent);//from  www . ja v a 2 s. c  o m
}

From source file:co.nerdart.ourss.fragment.EntriesListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share_starred: {
        String starredList = "";
        Cursor cursor = mEntriesCursorAdapter.getCursor();
        if (cursor != null && !cursor.isClosed()) {
            int titlePos = cursor.getColumnIndex(EntryColumns.TITLE);
            int linkPos = cursor.getColumnIndex(EntryColumns.LINK);
            if (cursor.moveToFirst()) {
                do {
                    starredList += cursor.getString(titlePos) + "\n" + cursor.getString(linkPos) + "\n\n";
                } while (cursor.moveToNext());
            }// w ww .ja  v a 2s  . c o  m
            startActivity(Intent.createChooser(
                    new Intent(Intent.ACTION_SEND)
                            .putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_favorites_title))
                            .putExtra(Intent.EXTRA_TEXT, starredList).setType(Constants.MIMETYPE_TEXT_PLAIN),
                    getString(R.string.menu_share)));
        }
        return true;
    }
    case R.id.menu_refresh: {
        if (!FetcherService.isRefreshingFeeds) {
            getActivity().startService(
                    new Intent(getActivity(), FetcherService.class).setAction(Constants.ACTION_REFRESH_FEEDS));
        }
        return true;
    }
    case R.id.menu_all_read: {
        mEntriesCursorAdapter.markAllAsRead();
        return true;
    }
    case R.id.menu_hide_read: {
        if (!PrefUtils.getBoolean(PrefUtils.SHOW_READ, true)) {
            PrefUtils.putBoolean(PrefUtils.SHOW_READ, true);
            item.setTitle(R.string.context_menu_hide_read).setIcon(R.drawable.hide_reads);
        } else {
            PrefUtils.putBoolean(PrefUtils.SHOW_READ, false);
            item.setTitle(R.string.context_menu_show_read).setIcon(R.drawable.view_reads);
        }
        return true;
    }
    case R.id.menu_settings: {
        startActivity(new Intent(getActivity(), GeneralPrefsActivity.class));
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:app.com.oz_heng.android.sunshine.DetailFragment.java

private Intent createShareForecastIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mForecast + FORECAST_SHARE_HASHTAG);
    return shareIntent;
}

From source file:com.crowflying.buildwatch.ConfigurationActivity.java

@Override
public boolean onPreferenceClick(Preference preference) {
    Log.d(LOG_TAG, String.format("Preference %s was clicked...", preference.getKey()));
    // Call the code for autosetup...
    if (PREFS_AUTOSETUP.equals(preference.getKey())) {
        Log.i(LOG_TAG, "Calling XZING.");
        tracker.trackEvent("configuration", "subscreen", "autosetup", 0L);

        IntentIntegrator integrator = new IntentIntegrator(this);
        integrator.setMessageByID(R.string.barcode_scanner_not_installed_message);
        integrator.initiateScan();//from w w  w.  j a v  a2  s. c  o m
        return true;
    }
    if (PREFS_FORGET_SETTINGS.equals(preference.getKey())) {
        Log.i(LOG_TAG, "Forgetting all settings");
        tracker.trackEvent("configuration", "action", "settings_cleared", 0L);
        PreferenceManager.getDefaultSharedPreferences(this).edit().clear().commit();
        return true;
    }
    if (PREFS_KEY_LAUNCH_WEBSITE.equals(preference.getKey())) {
        Log.i(LOG_TAG, "Launching website");
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(getString(R.string.config_launch_website_url)));
        startActivity(i);
        return true;
    }
    if (PREFS_KEY_GCM_TOKEN.equals(preference.getKey())) {
        String token = getPreferenceManager().getSharedPreferences().getString(PREFS_KEY_GCM_TOKEN, "");
        if (!TextUtils.isEmpty(token)) {
            Log.i(LOG_TAG, "Token clicked. Echoing it to the logfile for convencience: " + token);
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    getString(R.string.share_gcm_token_subject));
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, token);
            startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_gcm_token_using)));
        }
        return true;
    }
    return false;
}

From source file:org.peterbaldwin.client.android.tinyurl.SendTinyUrlActivity.java

private void send() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    Intent originalIntent = getIntent();
    if (Intent.ACTION_SEND.equals(originalIntent.getAction())) {
        // Copy extras from the original intent because they might contain
        // additional information about the URL (e.g., the title of a
        // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid
        // overwriting the TinyURL.
        intent.putExtras(originalIntent.getExtras());
    }//  w ww. j  ava2 s  .  co m

    intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl);
    try {
        CharSequence template = getText(R.string.title_send);
        String title = String.format(String.valueOf(template), mTinyUrl);
        startActivity(Intent.createChooser(intent, title));
        finish();
    } catch (ActivityNotFoundException e) {
        handleError(e);
    }
}

From source file:de.petendi.ethereum.android.EthereumAndroid.java

public void submitTransaction(Activity parentActivity, int requestCode, String transactionString) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setPackage(EthereumAndroidFactory.PACKAGENAME);
    intent.setData(Uri.parse("eth:" + transactionString));
    parentActivity.startActivityForResult(intent, requestCode);
}

From source file:ca.rmen.android.poetassistant.wotd.Wotd.java

private static PendingIntent getShareIntent(Context context, DictionaryEntry entry) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, buildWotdShareContent(context, entry));
    intent.setType("text/plain");
    return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UiUtils.setPreferenceTheme(this);
    super.onCreate(savedInstanceState);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    setContentView(R.layout.activity_feed_edit);
    setResult(RESULT_CANCELED);/*from w w w.  ja v a  2  s .  c  om*/

    Intent intent = getIntent();

    mNameEditText = (EditText) findViewById(R.id.feed_title);
    mUrlEditText = (EditText) findViewById(R.id.feed_url);
    mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext);
    mFiltersListView = (ListView) findViewById(android.R.id.list);
    View filtersLayout = findViewById(R.id.filters_layout);
    View buttonLayout = findViewById(R.id.button_layout);

    if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) {
        setTitle(R.string.new_feed_title);

        filtersLayout.setVisibility(View.GONE);

        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        }

        restoreInstanceState(savedInstanceState);
    } else if (intent.getAction().equals(Intent.ACTION_EDIT)) {
        setTitle(R.string.edit_feed_title);

        buttonLayout.setVisibility(View.GONE);

        mFiltersCursorAdapter = new FiltersCursorAdapter(this, null);
        mFiltersListView.setAdapter(mFiltersCursorAdapter);
        mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                startActionMode(mFilterActionModeCallback);
                mFiltersCursorAdapter.setSelectedFilter(position);
                mFiltersListView.invalidateViews();
                return true;
            }
        });

        getLoaderManager().initLoader(0, null, this);

        if (!restoreInstanceState(savedInstanceState)) {
            Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null);

            if (cursor.moveToNext()) {
                mPreviousName = cursor.getString(0);
                mNameEditText.setText(mPreviousName);
                mUrlEditText.setText(cursor.getString(1));
                mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1);
                cursor.close();
            } else {
                cursor.close();
                Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    }
}

From source file:com.activiti.android.app.fragments.content.ContentsFragment.java

@Subscribe
public void onDownloadTransferEvent(DownloadTransferEvent event) {
    if (event.hasException) {
        Snackbar.make(getActivity().findViewById(R.id.left_panel), event.exception.getMessage(),
                Snackbar.LENGTH_SHORT).show();
        return;/*www  . ja  v a2 s .c om*/
    }

    if (waitingDialog != null) {
        waitingDialog.dismiss();
    }

    try {
        switch (event.mode) {
        case ContentTransferSyncAdapter.MODE_SHARE:
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName());
            sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(event.data));
            sendIntent.setType(event.mimetype);
            getActivity().startActivity(
                    Intent.createChooser(sendIntent, getResources().getText(R.string.action_send_file)));
            break;
        case ContentTransferSyncAdapter.MODE_OPEN_IN:
            Intent viewIntent = new Intent(Intent.ACTION_VIEW);
            viewIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName());
            viewIntent.setDataAndType(Uri.fromFile(event.data), event.mimetype);
            startActivity(viewIntent);
            break;
        }
    } catch (ActivityNotFoundException e) {
        Snackbar.make(getActivity().findViewById(R.id.left_panel), R.string.file_editor_error_open,
                Snackbar.LENGTH_SHORT).show();
    }
}