“No Activity found to handle Intent” while emailing data

前端 未结 5 1012
深忆病人
深忆病人 2020-12-30 23:07

I am trying to mail data using this code:

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

        publi         


        
相关标签:
5条回答
  • 2020-12-30 23:21

    There's another subtle cause for this exception to occur.

    My app sends an email in two different conditions. One condition I set the To: field - it required Intent.ACTION_SENDTO

    But Intent.ACTION_SENDTO causes the described exeption in my other condition where To: is not supplied. In that condition Intent.ACTION_SEND was required.

    0 讨论(0)
  • 2020-12-30 23:25

    Call the StartActivity method in the following way:

        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");
    
    // FOLLOWING STATEMENT CHECKS WHETHER THERE IS ANY APP THAT CAN HANDLE OUR EMAIL INTENT 
    startActivity(Intent.createChooser(emailIntent,
                            "Send Email Using: "));
    

    If System do not find any eamil application, A nice Dialog will be shown:

    enter image description here


    I know that i am answering an old question, but maybe it can help someone.

    0 讨论(0)
  • 2020-12-30 23:30

    Yes problem was in emulator because it was not configured any email in emulator, if any one find this problem please configure email in your emulator, to do this

    select email from application menu and follow the steps.

    0 讨论(0)
  • 2020-12-30 23:35

    try to use this for better practice showing a message to the user to setup a mail application.

    try{
    
    // you email code here
    
    } catch (ActivityNotFoundException e) {
    // show message to user
    }
    
    0 讨论(0)
  • 2020-12-30 23:38

    I tested this on my device, and the code works perfectly. And I testet this code on an emulator, too, and it crashed. The problem is that the OS didn't find any activities which can handle this ACTION_SEND. Surround this kind of code all the time with a try/catch, since you can not be sure if there exists such an activity that can handle your intent. And try to install at least one app that can handle the ACTION_SEND, then try again, and see if it works for you.

    0 讨论(0)
提交回复
热议问题