problems with Action_send: ActivityNotFoundException

2

Hi, I'm executing action_send but I'm stopped by the application I'm using android 7 and with other versions it works but with this it stops.

String email = "[email protected]";

                    Intent intentMail = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"+email));

                    intentMail.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
                    intentMail.setType("plain/text");
                    intentMail.putExtra(Intent.EXTRA_SUBJECT, "mails title");
                    intentMail.putExtra(Intent.EXTRA_TEXT, "Hi there, i love Myform app..");
                    intentMail.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]","[email protected]"});
    startActivity(intentMail);
    
asked by Kevin Castaño 12.09.2017 в 04:07
source

1 answer

2

Surely you have an exception of ActivityNotFoundException , I suggest adding exception handling when you start the Activity:

try {
    startActivity(intentMail);
} catch(ActivityNotFoundException ex) {
    //Error no existe Activity.
}

It is important in this case that you have the Gmail application installed since you are specifying the package: "com.google.android.gm.ComposeActivityGmail"

I suggest you do not specify the Gmail package so that you can send the email with any client:

    String email = "[email protected]";
    Intent intentMail = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"+email));
  //intentMail.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
    intentMail.setType("plain/text");
    intentMail.putExtra(Intent.EXTRA_SUBJECT, "mails title");
    intentMail.putExtra(Intent.EXTRA_TEXT, "Hi there, i love Myform app..");
    intentMail.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]","[email protected]"});
        try {
            startActivity(intentMail);
        } catch(ActivityNotFoundException ex) {
            //Error no existe Activity.
        }
    
answered by 12.09.2017 / 05:46
source