Call Gmail app from my app. And email from my app

Asked

Viewed 971 times

1

I’ve researched both functions, but everything I find is very vague.

  1. I need to send an email from my app, directly to any email account (which is my user’s account).

  2. And my other problem is calling the Gmail app from my app.

Usage Intent/content Provider?

  • You want to attach some file too?

  • no. I just want to send a text, only!

2 answers

2

If you want to open only an email application with the email address of the addressee already completed just use this

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("mailto:" + url));
startActivity(intent);

If not the android page indicates using this form, more complete

public void composeEmail(String[] addresses, String subject) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_EMAIL, addresses);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

Website of the Android Developer:
https://developer.android.com/guide/components/intents-common.html?hl=pt-br#Email

1

You can use a Sharecompat.Intentbuilder if you are using a compatibility library.

final Intent intent = ShareCompat.IntentBuilder.from(getActivity())
                      .setType("message/rfc822")
                      .setSubject("Seu assunto")
                      .setText("corpo do email")
                      .setChooserTitle("Titulo da tela de seleção")
                      .createChooserIntent();

startActivity(intent);

With this code the user can select any application on the mobile that can send a message, among them the GMAIL.

I hope I’ve helped.

  • Do you have any feedback from that answer?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.