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

1

I have already researched the two functions, but everything I encounter is very vague.

  • I need to send an email from my application, directly to an email account (which is my user's).

  • And my other problem is to call the Gmail application from my app.

  • Use intent / content provider?

        
    asked by anonymous 09.12.2015 / 06:45

    2 answers

    2

    If you want to open only one email application with the recipient's email already filled in, just use this

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

    If not the android developer 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);
        }
    }
    

    Android Developer Page:
    link

        
    12.11.2017 / 03:37
    1

    You can use a ShareCompat.IntentBuilder if you are using 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 mobile application that can send a message, including GMAIL.

    I hope I have helped.

        
    09.12.2015 / 14:54