"No Activity found to handle Intent" while emailing data

Viewed 22454

I am trying to mail data using this code:

email = (Button) findViewById(R.id.enail);
    email.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            Intent emailIntent = new Intent(
                    android.content.Intent.ACTION_SEND);
            emailIntent.setAction(Intent.ACTION_SEND);
            emailIntent.setType("message/rfc822");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                    new String[] { "" });
            emailIntent.putExtra(android.content.Intent.EXTRA_CC, "");
            emailIntent.putExtra(android.content.Intent.EXTRA_BCC, "");
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Playlist Details");
            emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(Detail));
            emailIntent.setType("text/html");
            startActivity(emailIntent);

        }
    });

But it throws the following error:

07-17 12:31:33.438: E/AndroidRuntime(498): FATAL EXCEPTION: main
07-17 12:31:33.438: E/AndroidRuntime(498): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND (has extras) }
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.app.Activity.startActivityForResult(Activity.java:2817)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.app.Activity.startActivity(Activity.java:2923)
07-17 12:31:33.438: E/AndroidRuntime(498):  at com.playlist.ViewPlayList$3.onClick(ViewPlayList.java:93)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.view.View.performClick(View.java:2408)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.view.View$PerformClick.run(View.java:8816)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.os.Handler.handleCallback(Handler.java:587)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.os.Looper.loop(Looper.java:123)
07-17 12:31:33.438: E/AndroidRuntime(498):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-17 12:31:33.438: E/AndroidRuntime(498):  at java.lang.reflect.Method.invokeNative(Native Method)
07-17 12:31:33.438: E/AndroidRuntime(498):  at java.lang.reflect.Method.invoke(Method.java:521)
07-17 12:31:33.438: E/AndroidRuntime(498):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 12:31:33.438: E/AndroidRuntime(498):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 12:31:33.438: E/AndroidRuntime(498):  at dalvik.system.NativeStart.main(Native Method)

Please help me.

6 Answers

Also intent.resolveActivity(activity.getPackageManager()) can be used. The resolveActivity method checks whether exists Activity to handle intent or not.

Code example to call from Activity :

if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
} else {
    Toast.makeText(this, "No app to send email. Please install at least one", 
    Toast.LENGTH_SHORT).show();
}

And also check it out : https://medium.com/better-programming/the-imperfect-android-send-email-action-59610dfd1c2d

Related