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:net.networksaremadeofstring.rhybudd.ViewZenossEvent.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        finish();//from www. j  av  a 2  s .  co m
        return true;
    }

    case R.id.AddLog: {
        addMessageDialog = new Dialog(ViewZenossEvent.this);
        addMessageDialog.setContentView(R.layout.add_message);
        addMessageDialog.setTitle("Add Message to Event Log");
        ((Button) addMessageDialog.findViewById(R.id.SaveButton)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                AddLogMessage(((EditText) addMessageDialog.findViewById(R.id.LogMessage)).getText().toString());
                addMessageDialog.dismiss();
            }
        });

        addMessageDialog.show();
        return true;
    }

    case R.id.escalate: {
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

        // Add data to the intent, the receiving app will decide what to do with it.
        intent.putExtra(Intent.EXTRA_SUBJECT,
                "Escalation of Zenoss Event on " + getIntent().getStringExtra("Device"));
        String EventDetails = getIntent().getStringExtra("Summary") + "\r\r\n"
                + getIntent().getStringExtra("LastTime") + "\r\r\n" + "Count: "
                + getIntent().getIntExtra("Count", 0);

        intent.putExtra(Intent.EXTRA_TEXT, EventDetails);

        startActivity(Intent.createChooser(intent, "How would you like to escalate this event?"));
    }

    default: {
        return false;
    }
    }
}

From source file:com.activiti.android.app.fragments.task.TaskFormFragment.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;//from w ww .  j  a  v a 2s  .c om
    }

    hideWaiting();

    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();
    }
}

From source file:com.galois.qrstream.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setupUI();/*from   w  w w.  j  a v  a 2 s  .  co m*/
    hideUI();

    fragmentManager = getFragmentManager();
    transmitFragment = new TransmitFragment();
    receiveFragment = new ReceiveFragment();
    settingsFragment = new SettingsFragment();

    // Load application's default settings before user opens settings
    // screen because we want Rx and Tx to run with defaults.
    PreferenceManager.setDefaultValues(this, com.galois.qrstream.lib.R.xml.settings, false);

    if (savedInstanceState == null) {
        Intent startingIntent = getIntent();
        Log.d(Constants.APP_TAG, "startingIntent  " + startingIntent.getAction());
        if (startingIntent.getAction().equals(Intent.ACTION_SEND)) {
            try {
                Job job = buildJobFromIntent(startingIntent);
                Bundle bundle = new Bundle();
                bundle.putSerializable("job", job);
                transmitFragment.setArguments(bundle);
                showFragment(transmitFragment);
            } catch (IllegalArgumentException e) {
                Toast.makeText(this, "Unsupported media type.", Toast.LENGTH_LONG).show();
                finish();
            }
        } else {
            showFragment(receiveFragment);
        }
    }
}

From source file:com.cerema.cloud2.ui.dialog.ShareLinkToDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mIntent = getArguments().getParcelable(ARG_INTENT);
    String[] packagesToExclude = getArguments().getStringArray(ARG_PACKAGES_TO_EXCLUDE);
    List<String> packagesToExcludeList = Arrays
            .asList(packagesToExclude != null ? packagesToExclude : new String[0]);

    PackageManager pm = getActivity().getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(mIntent, PackageManager.MATCH_DEFAULT_ONLY);
    Iterator<ResolveInfo> it = activities.iterator();
    ResolveInfo resolveInfo;//from  w  w  w  . jav a 2 s.  c o  m
    while (it.hasNext()) {
        resolveInfo = it.next();
        if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())) {
            it.remove();
        }
    }

    boolean sendAction = mIntent.getBooleanExtra(Intent.ACTION_SEND, false);

    if (!sendAction) {
        // add activity for copy to clipboard
        Intent copyToClipboardIntent = new Intent(getActivity(), CopyToClipboardActivity.class);
        List<ResolveInfo> copyToClipboard = pm.queryIntentActivities(copyToClipboardIntent, 0);
        if (!copyToClipboard.isEmpty()) {
            activities.add(copyToClipboard.get(0));
        }
    }

    Collections.sort(activities, new ResolveInfo.DisplayNameComparator(pm));
    mAdapter = new ActivityAdapter(getActivity(), pm, activities);

    return createSelector(sendAction);

}

From source file:de.grobox.blitzmail.SendActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // before doing anything show notification about sending process
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setContentTitle(getString(R.string.sending_mail)).setContentText(getString(R.string.please_wait))
            .setSmallIcon(R.drawable.notification_icon).setOngoing(true);
    // Sets an activity indicator for an operation of indeterminate length
    mBuilder.setProgress(0, 0, true);/*from  w  w w .j a v  a2 s. co m*/
    // Create Pending Intent
    notifyIntent = new Intent(this, NotificationHandlerActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pendingIntent);
    // Issues the notification
    mNotifyManager.notify(0, mBuilder.build());

    Properties prefs;
    try {
        prefs = getPrefs();
    } catch (Exception e) {
        String msg = e.getMessage();

        Log.i("SendActivity", "ERROR: " + msg, e);

        if (e.getClass().getCanonicalName().equals("java.lang.RuntimeException") && e.getCause() != null
                && e.getCause().getClass().getCanonicalName().equals("javax.crypto.BadPaddingException")) {
            msg = getString(R.string.error_decrypt);
        }

        showError(msg);
        return;
    }

    // get and handle Intent
    Intent intent = getIntent();
    String action = intent.getAction();

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (action.equals(Intent.ACTION_SEND)) {
        String text = intent.getStringExtra(Intent.EXTRA_TEXT);
        //String email   = intent.getStringExtra(Intent.EXTRA_EMAIL);
        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        String cc = intent.getStringExtra(Intent.EXTRA_CC);
        String bcc = intent.getStringExtra(Intent.EXTRA_BCC);

        // Check for empty content
        if (subject == null && text != null) {
            // cut all characters from subject after the 128th
            subject = text.substring(0, (text.length() < 128) ? text.length() : 128);
            // remove line breaks from subject
            subject = subject.replace("\n", " ").replace("\r", " ");
        } else if (subject != null && text == null) {
            text = subject;
        } else if (subject == null && text == null) {
            Log.e("Instant Mail", "Did not send mail, because subject and body empty.");
            showError(getString(R.string.error_no_body_no_subject));
            return;
        }

        // create JSON object with mail information
        mMail = new JSONObject();
        try {
            mMail.put("id", String.valueOf(new Date().getTime()));
            mMail.put("body", text);
            mMail.put("subject", subject);
            mMail.put("cc", cc);
            mMail.put("bcc", bcc);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        // remember mail for later
        MailStorage.saveMail(this, mMail);

        // pass mail on to notification dialog class
        notifyIntent.putExtra("mail", mMail.toString());

        // Start Mail Task
        AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail);
        mail.execute();
    } else if (action.equals("BlitzMailReSend")) {
        try {
            mMail = new JSONObject(intent.getStringExtra("mail"));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        // pass mail on to notification dialog class
        notifyIntent.putExtra("mail", mMail.toString());

        // Start Mail Task
        AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail);
        mail.execute();
    }
    finish();
}

From source file:org.lol.reddit.activities.PostSubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit);

    typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type);
    usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username);
    subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit);
    titleEdit = (EditText) layout.findViewById(R.id.post_submit_title);
    textEdit = (EditText) layout.findViewById(R.id.post_submit_body);

    final Intent intent = getIntent();
    if (intent != null) {

        if (intent.hasExtra("subreddit")) {

            final String subreddit = intent.getStringExtra("subreddit");

            if (subreddit != null && subreddit.length() > 0 && !subreddit.matches("/?(r/)?all/?")
                    && subreddit.matches("/?(r/)?\\w+/?")) {
                subredditEdit.setText(subreddit);
            }/*from  w w w  .  jav  a  2  s .  c  o m*/

        } else if (Intent.ACTION_SEND.equalsIgnoreCase(intent.getAction())
                && intent.hasExtra(Intent.EXTRA_TEXT)) {
            final String url = intent.getStringExtra(Intent.EXTRA_TEXT);
            textEdit.setText(url);
        }

    } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) {
        titleEdit.setText(savedInstanceState.getString("post_title"));
        textEdit.setText(savedInstanceState.getString("post_body"));
        subredditEdit.setText(savedInstanceState.getString("subreddit"));
        typeSpinner.setSelection(savedInstanceState.getInt("post_type"));
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, R.string.error_toast_notloggedin);
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));
    typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes));

    // TODO remove the duplicate code here
    setHint();

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setHint();
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:ca.rmen.android.poetassistant.main.PagerAdapter.java

PagerAdapter(Context context, FragmentManager fm, Intent intent) {
    super(fm);//  www .ja  va 2  s  .c o m
    Log.v(TAG, "Constructor: intent = " + intent);
    mContext = context;
    Uri initialQuery = intent.getData();
    // Deep link to query in a specific tab
    if (initialQuery != null) {
        Tab tab = Tab.parse(initialQuery.getHost());
        if (tab == Tab.PATTERN) {
            mInitialPatternQuery = initialQuery.getLastPathSegment();
        } else if (tab == Tab.RHYMER) {
            mInitialRhymeQuery = initialQuery.getLastPathSegment();
        } else if (tab == Tab.THESAURUS) {
            mInitialThesaurusQuery = initialQuery.getLastPathSegment();
        } else if (tab == Tab.DICTIONARY) {
            mInitialDictionaryQuery = initialQuery.getLastPathSegment();
        } else if (Constants.DEEP_LINK_QUERY.equals(initialQuery.getHost())) {
            mInitialRhymeQuery = initialQuery.getLastPathSegment();
            mInitialThesaurusQuery = initialQuery.getLastPathSegment();
            mInitialDictionaryQuery = initialQuery.getLastPathSegment();
        }
    }
    // Text shared from another app:
    else if (Intent.ACTION_SEND.equals(intent.getAction())) {
        mInitialPoemText = intent.getStringExtra(Intent.EXTRA_TEXT);
    }
}

From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.byod_nfc_test_activity);

    mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
    mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mUserMangaer = (UserManager) getSystemService(Context.USER_SERVICE);
    mDisallowByPolicy = getIntent().getBooleanExtra(EXTRA_DISALLOW_BY_POLICY, false);
    if (mDisallowByPolicy) {
        mDevicePolicyManager.addUserRestriction(mAdminReceiverComponent, UserManager.DISALLOW_OUTGOING_BEAM);
    }//from   w  ww . j  a  va  2  s.c o  m

    final Uri uri = createUriForImage(SAMPLE_IMAGE_FILENAME, SAMPLE_IMAGE_CONTENT);
    Uri[] uris = new Uri[] { uri };

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    mNfcAdapter.setBeamPushUris(uris, this);

    findViewById(R.id.manual_beam_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mNfcAdapter.invokeBeam(NfcTestActivity.this);
        }
    });
    findViewById(R.id.intent_share_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
            shareIntent.setType("image/jpg");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            // Specify the package name of NfcBeamActivity so that the tester don't need to
            // select the activity manually.
            shareIntent.setClassName(NFC_BEAM_PACKAGE, NFC_BEAM_ACTIVITY);
            try {
                startActivity(shareIntent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(NfcTestActivity.this, R.string.provisioning_byod_cannot_resolve_beam_activity,
                        Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Nfc beam activity not found", e);
            }
        }
    });
}

From source file:com.battlelancer.seriesguide.ui.HelpActivity.java

private void sendEmail() {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType(HTTP.PLAIN_TEXT_TYPE);
    intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { SeriesGuidePreferences.SUPPORT_MAIL });
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
            "SeriesGuide " + Utils.getVersion(this) + " Feedback");
    intent.putExtra(android.content.Intent.EXTRA_TEXT, "");

    Intent chooser = Intent.createChooser(intent, getString(R.string.feedback));
    Utils.tryStartActivity(this, chooser, true);
}

From source file:org.quantumbadger.redreader.activities.PostSubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit);

    typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type);
    usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username);
    subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit);
    titleEdit = (EditText) layout.findViewById(R.id.post_submit_title);
    textEdit = (EditText) layout.findViewById(R.id.post_submit_body);

    final Intent intent = getIntent();
    if (intent != null) {

        if (intent.hasExtra("subreddit")) {

            final String subreddit = intent.getStringExtra("subreddit");

            if (subreddit != null && subreddit.length() > 0 && !subreddit.matches("/?(r/)?all/?")
                    && subreddit.matches("/?(r/)?\\w+/?")) {
                subredditEdit.setText(subreddit);
            }//from  ww  w  .  j a  v  a 2  s  .  c o  m

        } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND)
                && intent.hasExtra(Intent.EXTRA_TEXT)) {
            final String url = intent.getStringExtra(Intent.EXTRA_TEXT);
            textEdit.setText(url);
        }

    } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) {
        titleEdit.setText(savedInstanceState.getString("post_title"));
        textEdit.setText(savedInstanceState.getString("post_body"));
        subredditEdit.setText(savedInstanceState.getString("subreddit"));
        typeSpinner.setSelection(savedInstanceState.getInt("post_type"));
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, R.string.error_toast_notloggedin);
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));
    typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes));

    // TODO remove the duplicate code here
    setHint();

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setHint();
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}