Example usage for android.content Intent ACTION_SENDTO

List of usage examples for android.content Intent ACTION_SENDTO

Introduction

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

Prototype

String ACTION_SENDTO

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

Click Source Link

Document

Activity Action: Send a message to someone specified by the data.

Usage

From source file:com.scm.reader.resultPage.webview.ShortcutWebViewClient.java

public void overrideEmail(Uri uri) {
    Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
    sendIntent.setData(uri);
    context.startActivity(sendIntent);
}

From source file:saschpe.birthdays.fragment.SocialFragment.java

/**
 * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
 * has returned, but before any saved state has been restored in to the view.
 * This gives subclasses a chance to initialize themselves once
 * they know their view hierarchy has been completely created.  The fragment's
 * view hierarchy is not however attached to its parent at this point.
 *
 * @param view               The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
 * @param savedInstanceState If non-null, this fragment is being re-constructed
 *///from   www  .j  a  va  2 s  .  c  o m
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    provideFeedback.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String subject = getString(R.string.feedback_mail_subject_template, getString(R.string.app_name));

            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", SUPPORT_EMAIL_ADDRESS[0], null))
                            .putExtra(Intent.EXTRA_SUBJECT, subject).putExtra(Intent.EXTRA_TEXT, "")
                            .putExtra(Intent.EXTRA_EMAIL, SUPPORT_EMAIL_ADDRESS);
            startActivity(Intent.createChooser(emailIntent, view.getContext().getString(R.string.send_email)));
        }
    });
    followTwitter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("twitter://user?screen_name=" + TWITTER_NAME)));
            } catch (ActivityNotFoundException e) {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + TWITTER_NAME)));
            }
        }
    });
    rateOnPlayStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // To count with Play market back stack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
            if (Build.VERSION.SDK_INT >= 21) {
                flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
            } else {
                //noinspection deprecation
                flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
            }
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName))
                    .addFlags(flags);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + packageName)));
            }
        }
    });
    recommendToFriend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String subject = getString(R.string.get_app_template, getString(R.string.app_name));
            String body = Uri.parse("http://play.google.com/store/apps/details?id=" + packageName).toString();

            Intent sharingIntent = new Intent(Intent.ACTION_SEND).setType("text/plain")
                    .putExtra(Intent.EXTRA_SUBJECT, subject).putExtra(Intent.EXTRA_TEXT, body);
            startActivity(Intent.createChooser(sharingIntent, view.getContext().getString(R.string.share_via)));
        }
    });
    forkOnGithub.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://github.com/saschpe/BirthdayCalendar")));
        }
    });
}

From source file:com.android.messaging.datamodel.media.VCardResourceEntry.java

private static List<VCardResourceEntryDestinationItem> getContactInfoFromVCardEntry(final VCardEntry vcard) {
    final Resources resources = Factory.get().getApplicationContext().getResources();
    final List<VCardResourceEntry.VCardResourceEntryDestinationItem> retList = new ArrayList<VCardResourceEntry.VCardResourceEntryDestinationItem>();
    if (vcard.getPhoneList() != null) {
        for (final PhoneData phone : vcard.getPhoneList()) {
            final Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:" + phone.getNumber()));
            retList.add(new VCardResourceEntryDestinationItem(phone.getNumber(),
                    Phone.getTypeLabel(resources, phone.getType(), phone.getLabel()).toString(), intent));
        }/*from   w  w w  .  j av a2 s. c  om*/
    }

    if (vcard.getEmailList() != null) {
        for (final EmailData email : vcard.getEmailList()) {
            final Intent intent = new Intent(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse("mailto:"));
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email.getAddress() });
            retList.add(new VCardResourceEntryDestinationItem(email.getAddress(),
                    Phone.getTypeLabel(resources, email.getType(), email.getLabel()).toString(), intent));
        }
    }

    if (vcard.getPostalList() != null) {
        for (final PostalData postalData : vcard.getPostalList()) {
            String type;
            try {
                type = resources.getStringArray(android.R.array.postalAddressTypes)[postalData.getType() - 1];
            } catch (final NotFoundException ex) {
                type = resources.getStringArray(android.R.array.postalAddressTypes)[2];
            } catch (final Exception e) {
                LogUtil.e(LogUtil.BUGLE_TAG, "createContactItem postal Exception:" + e);
                type = resources.getStringArray(android.R.array.postalAddressTypes)[2];
            }
            Intent intent = new Intent(Intent.ACTION_VIEW);
            final String address = formatAddress(postalData);
            try {
                intent.setData(Uri.parse("geo:0,0?q=" + URLEncoder.encode(address, "UTF-8")));
            } catch (UnsupportedEncodingException e) {
                intent = null;
            }

            retList.add(new VCardResourceEntryDestinationItem(address, type, intent));
        }
    }

    if (vcard.getImList() != null) {
        for (final ImData imData : vcard.getImList()) {
            String type = null;
            try {
                type = resources.getString(Im.getProtocolLabelResource(imData.getProtocol()));
            } catch (final NotFoundException ex) {
                // Do nothing since this implies an empty label.
            }
            retList.add(new VCardResourceEntryDestinationItem(imData.getAddress(), type, null));
        }
    }

    if (vcard.getOrganizationList() != null) {
        for (final OrganizationData organtization : vcard.getOrganizationList()) {
            String type = null;
            try {
                type = resources.getString(Organization.getTypeLabelResource(organtization.getType()));
            } catch (final NotFoundException ex) {
                //set other kind as "other"
                type = resources.getStringArray(android.R.array.organizationTypes)[1];
            } catch (final Exception e) {
                LogUtil.e(LogUtil.BUGLE_TAG, "createContactItem org Exception:" + e);
                type = resources.getStringArray(android.R.array.organizationTypes)[1];
            }
            retList.add(new VCardResourceEntryDestinationItem(organtization.getOrganizationName(), type, null));
        }
    }

    if (vcard.getWebsiteList() != null) {
        for (final WebsiteData web : vcard.getWebsiteList()) {
            if (web != null && TextUtils.isGraphic(web.getWebsite())) {
                String website = web.getWebsite();
                if (!website.startsWith("http://") && !website.startsWith("https://")) {
                    // Prefix required for parsing to end up with a scheme and result in
                    // navigation
                    website = "http://" + website;
                }
                final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(website));
                retList.add(new VCardResourceEntryDestinationItem(web.getWebsite(), null, intent));
            }
        }
    }

    if (vcard.getBirthday() != null) {
        final String birthday = vcard.getBirthday();
        if (TextUtils.isGraphic(birthday)) {
            retList.add(new VCardResourceEntryDestinationItem(birthday,
                    resources.getString(R.string.vcard_detail_birthday_label), null));
        }
    }

    if (vcard.getNotes() != null) {
        for (final NoteData note : vcard.getNotes()) {
            final ArrayMap<String, String> curChildMap = new ArrayMap<String, String>();
            if (TextUtils.isGraphic(note.getNote())) {
                retList.add(new VCardResourceEntryDestinationItem(note.getNote(),
                        resources.getString(R.string.vcard_detail_notes_label), null));
            }
        }
    }
    return retList;
}

From source file:com.dm.material.dashboard.candybar.fragments.dialog.IntentChooserFragment.java

private void loadIntentChooser() {
    mLoadIntentChooser = new AsyncTask<Void, Void, Boolean>() {

        List<IntentChooser> apps;

        @Override/*from w  ww .  ja  va2  s. co  m*/
        protected void onPreExecute() {
            super.onPreExecute();
            apps = new ArrayList<>();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
                            getActivity().getResources().getString(R.string.dev_email), null));
                    List<ResolveInfo> resolveInfos = getActivity().getPackageManager()
                            .queryIntentActivities(intent, 0);
                    try {
                        Collections.sort(resolveInfos,
                                new ResolveInfo.DisplayNameComparator(getActivity().getPackageManager()));
                    } catch (Exception ignored) {
                    }

                    for (ResolveInfo resolveInfo : resolveInfos) {
                        switch (resolveInfo.activityInfo.packageName) {
                        case "com.google.android.gm":
                            apps.add(new IntentChooser(resolveInfo, IntentChooser.TYPE_RECOMMENDED));
                            break;
                        case "com.google.android.apps.inbox":
                            apps.add(new IntentChooser(resolveInfo, IntentChooser.TYPE_NOT_SUPPORTED));
                            break;
                        case "com.android.fallback":
                        case "com.paypal.android.p2pmobile":
                        case "com.lonelycatgames.Xplore":
                            break;
                        default:
                            apps.add(new IntentChooser(resolveInfo, IntentChooser.TYPE_SUPPORTED));
                            break;
                        }
                    }
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean && apps != null) {
                IntentAdapter adapter = new IntentAdapter(getActivity(), apps, mRequest);
                mIntentList.setAdapter(adapter);

                if (apps.size() == 0) {
                    mNoApp.setVisibility(View.VISIBLE);
                    setCancelable(true);
                }

                if (apps.size() == 1) {
                    if (apps.get(0).getApp().activityInfo.packageName.equals("com.google.android.apps.inbox"))
                        setCancelable(true);
                }
            } else {
                dismiss();
                Toast.makeText(getActivity(), R.string.intent_email_failed, Toast.LENGTH_LONG).show();
            }
            mLoadIntentChooser = null;
        }
    }.execute();
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an email Intent for the given message details and opens the application choooser for this Intent
 *
 * @param recipient the recipient's email address
 * @param subject the subject of the message
 * @param body the body text as a string
 * @param captionRes the string resource ID for the application chooser's window title
 * @param restrictToPackage an optional package name that the Intent may be restricted to (or null)
 * @param context the Context instance to start the Intent from
 * @throws Exception if there was an error trying to launch the email Intent
 *//* w  ww .  j av  a 2  s .co  m*/
public static void sendMail(final String recipient, final String subject, final String body,
        final int captionRes, final String restrictToPackage, final Context context) throws Exception {
    final String uriString = "mailto:" + Uri.encode(recipient) + "?subject=" + Uri.encode(subject) + "&body="
            + Uri.encode(body);
    final Uri uri = Uri.parse(uriString);
    final Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(uri);
    if (restrictToPackage != null && restrictToPackage.length() > 0) {
        emailIntent.setPackage(restrictToPackage);
        if (context != null) {
            // launch the target app directly
            context.startActivity(emailIntent);
        }
    } else {
        if (context != null) {
            // offer a selection of all applications that can handle the email Intent
            context.startActivity(Intent.createChooser(emailIntent, context.getString(captionRes)));
        }
    }
}

From source file:br.liveo.ndrawer.ui.fragment.FragmentContactus.java

@Override
public void onClick(View view) {

    Log.i("Main Fragment fragment", "on click");
    String tflag = null;//from   ww w .  j  ava2s .  c o  m

    switch (view.getId()) {

    case R.id.ivemail_dtu:
        Intent i = new Intent(Intent.ACTION_SENDTO);
        i.setData(Uri.parse("mailto:renaissance@dce.edu"));
        i.putExtra(Intent.EXTRA_SUBJECT, "Queries Regarding IET DTU Student Chapter");
        startActivity(i);

        break;
    case R.id.ivemail_mukcha:
        Intent i2 = new Intent(Intent.ACTION_SENDTO);
        i2.setData(Uri.parse("mailto:mukul0505@gmail.com"));
        i2.putExtra(Intent.EXTRA_SUBJECT, "Queries Regarding IET DTU Student Chapter");
        startActivity(i2);

        break;
    case R.id.ivemail_mukkum:
        Intent i3 = new Intent(Intent.ACTION_SENDTO);
        i3.setData(Uri.parse("mailto:mukulcj@gmail.com"));
        i3.putExtra(Intent.EXTRA_SUBJECT, "Queries Regarding IET DTU Student Chapter");
        startActivity(i3);

        break;
    case R.id.ivcall_mukcha:
        Intent i4 = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:9873113748"));
        startActivity(i4);

        break;
    case R.id.ivcall_mukkum:
        Intent i5 = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:9013616477"));
        startActivity(i5);

        break;

    }

}

From source file:cz.maresmar.sfm.app.SfmApp.java

private void sendFeedback(Context context, String subject) {
    Timber.i("Device %s (%s) on SDK %d", Build.DEVICE, Build.MANUFACTURER, Build.VERSION.SDK_INT);

    File logFile = getLogFile();/*ww w . j  av a2  s  . co  m*/
    Uri logUri = FileProvider.getUriForFile(this, "cz.maresmar.sfm.FileProvider", logFile);

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "mmrmartin+dev" + '@' + "gmail.com" });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "[sfm] " + subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.feedback_mail_text));
    emailIntent.putExtra(Intent.EXTRA_STREAM, logUri);
    emailIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(emailIntent,
            PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resInfoList) {
        String packageName = resolveInfo.activityInfo.packageName;
        context.grantUriPermission(packageName, logUri,
                Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

    context.startActivity(
            Intent.createChooser(emailIntent, getString(R.string.feedback_choose_email_app_dialog)));
}

From source file:org.teleportr.activity.Autocompletion.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.about:
        startActivity(new Intent(this, About.class));
        break;/*from w  w  w .ja va  2s  .c  o m*/

    case R.id.refresh:
        new FetchNearbyDownloads().execute("");
        break;

    case R.id.feedback:
        new AlertDialog.Builder(this).setTitle("feedback").setIcon(android.R.drawable.ic_dialog_info)
                .setPositiveButton("send logs", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        LogCollector.feedback(Autocompletion.this, "scotty@teleportr.org, flo@andlabs.de");
                    }
                }).setNeutralButton("mail scotty", new Dialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_SENDTO,
                                Uri.parse("mailto:scotty@teleportr.org, flo@andlabs.de"));
                        intent.putExtra(Intent.EXTRA_SUBJECT, "feedback " + getString(R.string.app_name));
                        try {
                            PackageInfo info = getPackageManager().getPackageInfo("org.teleportr",
                                    PackageManager.GET_META_DATA);
                            intent.putExtra(Intent.EXTRA_TEXT,
                                    "version: " + info.versionName + " (" + info.versionCode + ") \n");
                        } catch (NameNotFoundException e) {
                        }
                        startActivity(intent);
                    }
                }).show();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java

private void initializeButtons() {
    initializeServiceButtons();/*ww  w.j  a v  a 2  s  .c  om*/
    initializeDemoButton();
    initializeEnableNotificationButton();

    mImproveTransliterationTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String uriText = "mailto:android@abhijitvalluri.com" + "?subject="
                    + Uri.encode("Improve Transliterations for <SPECIFY_LANGUAGE>") + "&body="
                    + Uri.encode("<MESSAGE>");

            Uri uri = Uri.parse(uriText);

            Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
            sendIntent.setData(uri);
            startActivity(Intent.createChooser(sendIntent, "Send email"));
        }
    });

    mRateAppTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse("market://details?id=" + Constants.PACKAGE_NAME);
            Intent gotoPlayStore = new Intent(Intent.ACTION_VIEW, uri);
            // To count with Play market backstack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            gotoPlayStore.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(gotoPlayStore);
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + Constants.PACKAGE_NAME)));
            }
        }
    });
}

From source file:id.satusatudua.sigap.ui.fragment.SettingFragment.java

private void sendFeedBack(String feedback) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:zetra@mail.ugm.ac.id"));
    intent.putExtra(Intent.EXTRA_SUBJECT, "Sigap Feedback");
    intent.putExtra(Intent.EXTRA_TEXT, feedback + "\n\nDikirim melalui aplikasi Sigap.");
    startActivity(intent);// www  .j av a2  s.  com

}