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.ae.apps.messagecounter.activities.MainActivity.java

private Intent getShareIntent() {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.play_store_url));
    return shareIntent;
}

From source file:com.codebutler.farebot.fragment.CardsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getActivity()
            .getSystemService(Context.CLIPBOARD_SERVICE);
    try {/*  www . ja v  a  2 s .  co  m*/
        int itemId = item.getItemId();
        switch (itemId) {
        case R.id.import_file:
            Intent target = new Intent(Intent.ACTION_GET_CONTENT);
            target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Environment.getExternalStorageDirectory()));
            target.setType("*/*");
            startActivityForResult(Intent.createChooser(target, getString(R.string.select_file)),
                    REQUEST_SELECT_FILE);
            return true;
        case R.id.import_clipboard:
            ClipData clip = clipboardManager.getPrimaryClip();
            if (clip != null && clip.getItemCount() > 0) {
                String text = clip.getItemAt(0).coerceToText(getActivity()).toString();
                onCardsImported(mExportHelper.importCards(text));
            }
            return true;
        case R.id.copy:
            clipboardManager.setPrimaryClip(ClipData.newPlainText(null, mExportHelper.exportCards()));
            Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.share:
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, mExportHelper.exportCards());
            startActivity(intent);
            return true;
        case R.id.save:
            exportToFile();
            return true;
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
    return false;
}

From source file:com.armtimes.activities.SingleArticlePreviewActivity.java

private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    // Get Description.
    String description = getIntent().getStringExtra(EXTRA_SHORT_DESC);
    if (description == null || description.isEmpty())
        return null;

    String url = getIntent().getStringExtra(EXTRA_URL);
    if (url == null || url.isEmpty())
        return null;

    description = Html.fromHtml(description).toString();

    final String textToShare = String.format("%s... <a href=\"%s\">%s</a>", description, url,
            getString(R.string.read_more));
    shareIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
    return shareIntent;
}

From source file:com.digitalarx.android.files.FileOperationsHelper.java

public void sendDownloadedFile(OCFile file) {
    if (file != null) {
        Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
        // set MimeType
        sendIntent.setType(file.getMimetype());
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getStoragePath()));
        sendIntent.putExtra(Intent.ACTION_SEND, true); // Send Action

        // Show dialog, without the own app
        String[] packagesToExclude = new String[] { mFileActivity.getPackageName() };
        DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude, file);
        chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);

    } else {//from  ww  w  .  j a v  a2  s  .  c om
        Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
    }
}

From source file:fr.seeks.SuggestionProvider.java

public void setCursorOfQueryThrow(Uri uri, String query, MatrixCursor matrix)
        throws MalformedURLException, IOException {
    String url = getUrlFromKeywords(query);
    Log.v(TAG, "Query:" + url);

    String json = null;/*from   w ww.j  a  v  a2  s  . c o m*/

    while (json == null) {
        HttpURLConnection connection = null;
        connection = (HttpURLConnection) (new URL(url)).openConnection();

        try {
            connection.setDoOutput(true);
            connection.setChunkedStreamingMode(0);
            connection.setInstanceFollowRedirects(true);

            connection.connect();
            int response = connection.getResponseCode();
            if (response == HttpURLConnection.HTTP_MOVED_PERM
                    || response == HttpURLConnection.HTTP_MOVED_TEMP) {
                Map<String, List<String>> list = connection.getHeaderFields();
                for (Entry<String, List<String>> entry : list.entrySet()) {
                    String value = "";
                    for (String s : entry.getValue()) {
                        value = value + ";" + s;
                    }
                    Log.v(TAG, entry.getKey() + ":" + value);
                }
                // FIXME
                url = "";
                return;
            }
            InputStream in = connection.getInputStream();

            BufferedReader r = new BufferedReader(new InputStreamReader(in));
            StringBuilder builder = new StringBuilder();

            String line;
            while ((line = r.readLine()) != null) {
                builder.append(line);
            }

            json = builder.toString();

            /*
             * Log.v(TAG, "** JSON START **"); Log.v(TAG, json); Log.v(TAG,
             * "** JSON END **");
             */
        } catch (IOException e) {
            e.printStackTrace();
            return;
        } finally {
            connection.disconnect();
        }
    }

    JSONArray snippets;
    JSONObject object;
    JSONArray suggestions;

    Boolean show_snippets = mPrefs.getBoolean("show_snippets", false);
    if (show_snippets) {
        try {
            object = (JSONObject) new JSONTokener(json).nextValue();
            snippets = object.getJSONArray("snippets");
        } catch (JSONException e) {
            e.printStackTrace();
            return;
        }
        Log.v(TAG, "Snippets found: " + snippets.length());
        for (int i = 0; i < snippets.length(); i++) {
            JSONObject snip;
            try {
                snip = snippets.getJSONObject(i);
                matrix.newRow().add(i).add(snip.getString("title")).add(snip.getString("summary"))
                        .add(snip.getString("title")).add(Intent.ACTION_SEND).add(snip.getString("url"));
            } catch (JSONException e) {
                e.printStackTrace();
                continue;
            }
        }
    } else {
        try {
            object = (JSONObject) new JSONTokener(json).nextValue();
            suggestions = object.getJSONArray("suggestions");
        } catch (JSONException e) {
            e.printStackTrace();
            return;
        }
        Log.v(TAG, "Suggestions found: " + suggestions.length());
        for (int i = 0; i < suggestions.length(); i++) {
            try {
                matrix.newRow().add(i).add(suggestions.getString(i)).add("").add(suggestions.getString(i))
                        .add(Intent.ACTION_SEARCH).add("");
            } catch (JSONException e) {
                e.printStackTrace();
                continue;
            }
        }
    }
    getContext().getContentResolver().notifyChange(uri, null);

}

From source file:com.cmput301.recipebot.ui.AbstractRecipeActivity.java

/**
 * Creates a sharing {@link android.content.Intent}.
 * Shares mRecipe, doesn't get it from the UI.
 *
 * @return The sharing intent.// w  w  w.  j  a  va2  s .co m
 */
private static Intent createShareIntent(Recipe recipe, File file) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, recipe.getName());
    shareIntent.putExtra(Intent.EXTRA_TITLE, recipe.getName());
    shareIntent.putExtra(Intent.EXTRA_TEXT, recipe.toEmail());
    shareIntent.setType("application/json");
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    return shareIntent;
}

From source file:com.maass.android.imgur_uploader.ImgurUpload.java

/**
 * /*from   w ww .  ja v a2  s.  co  m*/
 * @return a map that contains objects with the following keys:
 * 
 *         delete - the url used to delete the uploaded image (null if
 *         error).
 * 
 *         original - the url to the uploaded image (null if error) The map
 *         is null if error
 */
private Map<String, String> handleSendIntent(final Intent intent) {
    Log.i(this.getClass().getName(), "in handleResponse()");

    Log.d(this.getClass().getName(), intent.toString());
    final Bundle extras = intent.getExtras();
    try {
        //upload a new image
        if (Intent.ACTION_SEND.equals(intent.getAction()) && (extras != null)
                && extras.containsKey(Intent.EXTRA_STREAM)) {

            final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (uri != null) {
                Log.d(this.getClass().getName(), uri.toString());
                // store uri so we can create the thumbnail if we succeed
                imageLocation = uri;
                final String jsonOutput = readPictureDataAndUpload(uri);
                return parseJSONResponse(jsonOutput);
            }
            Log.e(this.getClass().getName(), "URI null");
        }
    } catch (final Exception e) {
        Log.e(this.getClass().getName(), "Completely unexpected error", e);
    }
    return null;
}

From source file:com.code.android.vibevault.FeaturedShowsScreen.java

/** Handle user's long-click selection.
*
*//*from  ww w  . j  a  va2s .co  m*/
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (menuInfo != null) {
        ArchiveShowObj selShow = (ArchiveShowObj) featuredShowsList.getAdapter().getItem(menuInfo.position);
        switch (item.getItemId()) {
        case VibeVault.EMAIL_LINK:
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Great show on archive.org: " + selShow.getArtistAndTitle());
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                    "Hey,\n\nYou should listen to " + selShow.getArtistAndTitle() + ".  You can find it here: "
                            + selShow.getShowURL() + "\n\nSent using VibeVault for Android.");
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
            return true;
        case (VibeVault.ADD_TO_FAVORITE_LIST):
            VibeVault.db.insertFavoriteShow(selShow);
            return true;
        default:
            break;
        }
        return false;
    }
    return true;
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * ?Intent??//w ww . j  a  v  a  2  s.  c om
 */
public static Intent createSendTextIntent(String text) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    return intent;
}

From source file:ca.rmen.android.poetassistant.main.reader.ReaderFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_new) {
        ConfirmDialogFragment.show(ACTION_FILE_NEW, getString(R.string.file_new_confirm_title),
                getString(R.string.action_clear), getChildFragmentManager(), DIALOG_TAG);
    } else if (item.getItemId() == R.id.action_open) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            open();//from   w  w w  .ja  va  2s. c om
    } else if (item.getItemId() == R.id.action_save) {
        PoemFile poemFile = mPoemPrefs.getSavedPoem();
        PoemFile.save(getActivity(), poemFile.uri, mBinding.tvText.getText().toString(), this);
    } else if (item.getItemId() == R.id.action_save_as) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            saveAs();
    } else if (item.getItemId() == R.id.action_share) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, mBinding.tvText.getText().toString());
        intent.setType("text/plain");
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
    }
    return true;
}