ActivityNotFoundException while sending email from the application

前端 未结 3 1701
臣服心动
臣服心动 2021-01-11 12:15

I have written a code in which I am allowing user to send order via email to vendor [ShopOwner] along with their personal and cart item details, but here I am getti

3条回答
  •  遥遥无期
    2021-01-11 12:37

    The error message shows:

    ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/html flg=0x1 (has clip) (has extras) }

    It means that the android system doesnt found any email sending activity to handle the intent created by you. Make sure you have email application installed in your device.

    Also use the following code to send email,

    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();
    }
    

提交回复
热议问题