从应用程序发送电子邮件时发生ActivityNotFoundException

时间:2013-01-30 12:44:49

标签: android email android-intent android-emulator

我编写了一个代码,我允许用户通过电子邮件向供应商[ShopOwner]发送订单以及他们的个人和购物车商品详细信息,但在这里我得到了

错误:不幸的是App已停止

logcat的:

01-30 17:56:14.605: E/AndroidRuntime(951): FATAL EXCEPTION: main
01-30 17:56:14.605: E/AndroidRuntime(951): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/html flg=0x1 (has clip) (has extras) }
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivityForResult(Activity.java:3370)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivityForResult(Activity.java:3331)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivity(Activity.java:3566)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.Activity.startActivity(Activity.java:3534)
01-30 17:56:14.605: E/AndroidRuntime(951):  at com.version.bajrang.january.menu.ArrowsActivity$1.onClick(ArrowsActivity.java:105)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.view.View.performClick(View.java:4202)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.view.View$PerformClick.run(View.java:17340)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.os.Handler.handleCallback(Handler.java:725)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.os.Looper.loop(Looper.java:137)
01-30 17:56:14.605: E/AndroidRuntime(951):  at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 17:56:14.605: E/AndroidRuntime(951):  at java.lang.reflect.Method.invokeNative(Native Method)
01-30 17:56:14.605: E/AndroidRuntime(951):  at java.lang.reflect.Method.invoke(Method.java:511)
01-30 17:56:14.605: E/AndroidRuntime(951):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 17:56:14.605: E/AndroidRuntime(951):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 17:56:14.605: E/AndroidRuntime(951):  at dalvik.system.NativeStart.main(Native Method)

代码:

Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "rakesh@rocketmail.com" };   
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
messageIntent.setType("text/html");
messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body.toString()));
startActivity(messageIntent);

最后在SahilMahajanMj的帮助下,我使用了这段代码几乎没有变化:

 Intent i = new Intent(Intent.ACTION_SEND);
 i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"rakesh@rocketmail.com"});
 i.putExtra(Intent.EXTRA_SUBJECT, subject);
 i.setType("message/rfc822");
 i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body.toString()));

try {
    startActivity(Intent.createChooser(i, "Send email via :"));
    Toast.makeText(ArrowsActivity.this, "Email Sent.", Toast.LENGTH_SHORT).show();
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(ArrowsActivity.this, "There are no email applications installed.", Toast.LENGTH_SHORT).show();
}

ViewCartActivity.java

public void onClick(View v) {
    // TODO Auto-generated method stub

        Intent mViewCartIntent = new Intent(ViewCartActivity.this, com.version.bajrang.january.menu.ArrowsActivity.class);
        mViewCartIntent.putExtra("name", myTextVeiwGrandTotal.getText().toString());
        startActivity(mViewCartIntent);

            }
        });

ArrowsActivity.java中:

TextView txtName = (TextView) findViewById(R.id.total);
Intent i = getIntent();
String name = i.getStringExtra("name");
txtName.setText(name);

我使用上面的代码来获取购物车中的产品总数,我也可以获得并显示,但是这里购物车中的商品总数我也希望在购物车标签上显示如下:

https://play.google.com/store/apps/details?id=com.queppelin.tastykhana

他们用红色表示2 ......

4 个答案:

答案 0 :(得分:17)

错误消息显示:

  

ActivityNotFoundException:找不到处理Intent的Activity {   act = android.intent.action.SEND typ = text / html flg = 0x1(has clip)(有   额外的)}

这意味着android系统没有找到任何电子邮件发送活动来处理您创建的意图。确保您的设备中安装了电子邮件应用程序。

还可以使用以下代码发送电子邮件,

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
    startActivity(Intent.createChooser(i, "Send mail"));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email applications installed.", Toast.LENGTH_SHORT).show();
}

答案 1 :(得分:5)

Rakesh抱歉迟到的回复,因为上午10点我试图解决你的问题,我已经尝试了几次,最后下面的代码工作:

我知道你得到了答案,但我已经花了很多时间让我满意,我在这里提出答案,兄弟我不需要积分,因为@SahilMahajanMj值得这样:

  Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"rakesh@rocketmail.com"});
        i.putExtra(Intent.EXTRA_SUBJECT, subject);
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body.toString()));

        try {
            startActivity(Intent.createChooser(i, "Send email via :"));
            } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(ArrowsActivity.this, "There are no email applications installed.", Toast.LENGTH_SHORT).show();
        }

答案 2 :(得分:3)

您使用android.content传递putExtras的问题。

尝试以下内容:

public Intent sendMail1() {
        Intent messageIntent = new Intent(Intent.ACTION_SEND);

        String aEmailList[] = { "rakesh@rocketmail.com" };
        messageIntent.putExtra(Intent.EXTRA_EMAIL, aEmailList);

        messageIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

        messageIntent.setType("text/html");
        messageIntent.putExtra(Intent.EXTRA_TEXT,
                Html.fromHtml(body.toString()));

        return messageIntent;
    }

点燃你的意图:

startActivity(Intent.createChooser(sendMail1(), "send mail"));

答案 3 :(得分:0)

How to manage `startActivityForResult` on Android?

看到此链接如何使用startactivity结果它将解决您的问题朋友。