0

I am having a problem with android email intent.....i need to open email app so that the user can provide feedback for my app.It doesn't open when i use this..throws an ActivityNotFoundException .....i am using my phone ,not an emulator and my phone has email and gmail apps in it. Help me solve?? Here is my code:

    Intent intent= new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:"));
    intent.setType("text/plain");
    String[] mail={"someone@gmail.com"};
    intent.putExtra(Intent.EXTRA_SUBJECT,"");
    intent.putExtra(Intent.EXTRA_TEXT,"");
    intent.putExtra(Intent.EXTRA_EMAIL,mail);
    startActivity(intent);

Any and all comments are appreciated :)

sumanth
  • 135
  • 1
  • 10

3 Answers3

1

For your case, what ActivityNotFoundException most likely means that in your phone you don't have any default email app email application installed on your device like Gmail, so when you launch the Intent you receive this error.

You can try to handle that exception like this:

try {
    startActivity(Intent.createChooser(i, "Send mail"));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(Activity.this, "no email app",Toast.LENGTH_SHORT).show();
}
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
0

From the android docs, An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object. This type of intent is called an implicit intent because it does not specify the app component to start, but instead specifies an action and provides some data with which to perform the action.

When you call startActivity() or startActivityForResult() and pass it an implicit intent, the system resolves the intent to an app that can handle the intent and starts its corresponding Activity. If there's more than one app that can handle the intent, the system presents the user with a dialog to pick which app to use.`

So, in your case, the system couldn't find an app to resolve the intent to as @Tamir mentioned.

For more information , look into this Stack Overflow post: Send Email Intent

Tony Okoth
  • 157
  • 1
  • 4
-2

it works for me :

      String[] recipients;
            Intent intent = new Intent(Intent.ACTION_SEND);
                recipients = new String[]{"someone@gmail.com"};    

            intent.putExtra(Intent.EXTRA_EMAIL, recipients);
            intent.setType("text/html");
            intent.setPackage("com.google.android.gm");
           try {
            activity.startActivity(Intent.createChooser(intent, "Send"));
      }
         catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(Activity.this, "no email app",Toast.LENGTH_SHORT).show();
}
Mohammad Sommakia
  • 1,773
  • 3
  • 15
  • 48
  • `plain/text` is not a valid MIME type. Do not hack into another app by assuming that `com.google.android.gm.ComposeActivityGmail` is always going to be the proper activity, let alone one that is exported. Do not assume that all users want to use Gmail. Do not put an invalid `Uri` into an `Intent`, and `test@gmail.com` is not a valid `Uri`. `ACTION_VIEW` does not support `EXTRA_EMAIL`, `EXTRA_SUBJECT`, or `EXTRA_TEXT`. – CommonsWare Jun 15 '19 at 13:42