Shreya
Shreya

Reputation: 39

I get an error" No application can perform this action" while sending an email

Here is the code, everythin works well except the no application can perform this action "error..Please let me know what is the mistake in the code.

 public void sends(View button) {   
        // Do click handling here  


        final EditText date = (EditText) findViewById(R.id.editText1);  
        String da = date.getText().toString();  

        final EditText phone = (EditText) findViewById(R.id.editText2);  
        String ph = phone.getText().toString();  

        final EditText nameplate = (EditText) findViewById(R.id.editText3);  
        String np = nameplate.getText().toString(); 

        final EditText issue = (EditText) findViewById(R.id.editText4);  
        String i = issue.getText().toString(); 

        StringBuilder s= new StringBuilder(100);
        s.append(da);
        s.append(". ");
        s.append(ph);
        s.append(". ");
        s.append(np);
        s.append(". ");
        s.append(i);

        String st=s.toString();




        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
        //emailIntent.setType("plain/text");
        //startActivity(emailIntent); 
        startActivity(Intent.createChooser(emailIntent, "Send your email in:"));

        Intent emailIntentt= new Intent(android.content.Intent.ACTION_SEND);  

        String aEmailList[] = { "[email protected]" };  


        emailIntentt.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);  
        //emailIntentt.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);  
        //emailIntentt.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);  

        emailIntentt.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback");  

        emailIntentt.setType("message/rfc822");  
        emailIntentt.putExtra(android.content.Intent.EXTRA_TEXT, st);




        startActivityForResult(emailIntentt, REQUEST_SEND_MAIL);
    } 
    public static final int REQUEST_SEND_MAIL = 1;

    public void onActivityResult(int requestCode, int resultCode, Intent data) {



        switch (requestCode) {
        case REQUEST_SEND_MAIL:
            // When the request to send mail returns
            if (resultCode == Activity.RESULT_OK) {
                Toast.makeText(this, "message successfully sent", Toast.LENGTH_SHORT).show();

            } else {
                Toast.makeText(this, "sorry", Toast.LENGTH_SHORT).show();
            }

            }}

Upvotes: 2

Views: 8902

Answers (5)

Evgeny TImofeev
Evgeny TImofeev

Reputation: 41

This helped me:

String email = person.getEmail();
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(Intent.EXTRA_SUBJECT, "Happy Birthday!");
intent.setData(Uri.parse("mailto:" + email));
context.startActivity(Intent.createChooser(intent, "Send e-mail to"));

There are many answers about Uri.fromParts() method, but the only thing that helped after hours of headache Uri.parse();

By clicking i get all email apps installed on my phone.

Upvotes: 4

iTurki
iTurki

Reputation: 16398

You have startActivity() and startActivityForResult!!! You need one. That's why the first intent gets fired and there is no app to catch it.

Try this:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);   
String aEmailList[] = { "[email protected]" };  

emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback");   
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, st);

startActivityForResult(emailIntent, REQUEST_SEND_MAIL);

Upvotes: 0

user1556613
user1556613

Reputation:

remove either startActivity() or startActivityForResult()

Upvotes: 0

Manoj Kumar
Manoj Kumar

Reputation: 1520

2 Suggestions i got for u:

1, Run it in a Google API targeted emulator or run it in a device

2, first sign in ur email account before u run this app :)

cheers

Upvotes: 0

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28541

I'd say your problem is that emailIntentt.setType("message/rfc822");. Set the type to "plain/text".

Also don't start two activities, one will be enough, simply use the chooser.

Upvotes: 1

Related Questions