Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Activity found to handle Intent while sending email

I am trying to send the picture clicked through my application as an attachment via email. The picture is clicked and I get the path correctly but the application throws me a run time exception.."No activity found to handle Intent". I am testing this on my device and I have my gmail account configured. I am not sure how to resolve this. Please help.

This is my code:

public static void sendEmail(Context context, String[] recipientList, String title, String subject, String body) {

Intent intent = new Intent(Intent.ACTION_SENDTO,    Uri.parse("mailto:[email protected]"));
        intent.setType("plain/text");
        intent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientList);
        intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(android.content.Intent.EXTRA_TEXT, body);
        intent.putExtra(Intent.EXTRA_STREAM, capturedImageFilePath);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

}

And this is the log:

01-15 11:26:04.455: E/AndroidRuntime(9904): FATAL EXCEPTION: main
01-15 11:26:04.455: E/AndroidRuntime(9904): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO typ=plain/text flg=0x10000000 (has extras) }
01-15 11:26:04.455: E/AndroidRuntime(9904):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
01-15 11:26:04.455: E/AndroidRuntime(9904):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
01-15 11:26:04.455: E/AndroidRuntime(9904):     at android.app.ContextImpl.startActivity(ContextImpl.java:852)
01-15 11:26:04.455: E/AndroidRuntime(9904):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
01-15 11:26:04.455: E/AndroidRuntime(9904):     at com.example.attachmail.AttchmentActivity.sendEmail(AttchmentActivity.java:133)
01-15 11:26:04.455: E/AndroidRuntime(9904):     at com.example.attachmail.AttchmentActivity$2.onClick(AttchmentActivity.java:93)
like image 703
Nisha Avatar asked Jan 15 '13 06:01

Nisha


2 Answers

I had a similier issue, I have pass the parameters fo a function which sends the email with an intent. However I notice that the I needed to use the line intent.setData(Uri uri) and if the email parameter was just email then it needs to be with "mailto:" text Example:

intent.setData(Uri.parse("mailto:"+email));

like here:

Intent intent = new Intent(Intent.ACTION_SENDTO);
                    intent.setType("message/rfc822");
                    intent.putExtra(Intent.EXTRA_EMAIL, email);
                    intent.setData(Uri.parse("mailto:"+email));
                    intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                    intent.putExtra(Intent.EXTRA_TEXT, emailContent);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
                try {

                    startActivity(intent);
                } catch (android.content.ActivityNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.d("Email error:",e.toString());
                }

If you are testing it on an emulator there might be a problem with "Sharing" apps not configured, so either make sure to set it on the emulator or test it on an actual device.

like image 118
Gil Allen Avatar answered Nov 11 '22 09:11

Gil Allen


Try the following code to send email.

                   Intent sendIntent = new Intent(Intent.ACTION_SEND);

                    sendIntent.setType("message/rfc822");
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                   sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(path));

                   sendIntent.putExtra(Intent.EXTRA_TEXT, body);
                   startActivity(Intent.createChooser(sendIntent, "Email:")) 
like image 27
Priya Avatar answered Nov 11 '22 08:11

Priya