Reputation: 75
I'm using C# for Visual studio, and i wanted to send an Email through my app, but i always get an error
here's my code
Button button = FindViewById<Button>(Resource.Id.myButton);
button.Click += delegate
{
var email = new Intent(Android.Content.Intent.ActionSend);
email.PutExtra(Android.Content.Intent.ExtraEmail, new string[] { "[email protected]", "[email protected]" });
email.PutExtra(Android.Content.Intent.ExtraCc, new string[] { "[email protected]" });
email.PutExtra(Android.Content.Intent.ExtraSubject, "Hello Email");
email.PutExtra(Android.Content.Intent.ExtraText, "Hello user");
email.SetType("message/rfc822");
StartActivity(email);
};
and i always get this error
Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=message/rfc822 flg=0x1 (has clip) (has extras) }
can someone help me?
Upvotes: 0
Views: 431
Reputation: 1677
I means that it can't find an activity to handle the action SEND. Are you running this on code in a simulator? Try it on a physical device (make sure it has a mail client installed).
Also, I would surround your code in a try/catch block, to avoid crashing if there's no activity available to handle your intent.
** Update **
Here's an example. Put the try/catch block inside your delegate.
try
{
var email = new Intent(Android.Content.Intent.ActionSend);
email.PutExtra(Android.Content.Intent.ExtraEmail, new string[] { "[email protected]", "[email protected]" });
email.PutExtra(Android.Content.Intent.ExtraCc, new string[] { "[email protected]" });
email.PutExtra(Android.Content.Intent.ExtraSubject, "Hello Email");
email.PutExtra(Android.Content.Intent.ExtraText, "Hello user");
email.SetType("message/rfc822");
StartActivity(email);
}
catch (Exception ex)
{
// Either ignore or log the error.
}
Upvotes: 2