简体   繁体   中英

Unable to send email through email intent

I have had the email intent of android working before with my GMail account on the emulator.

I have come back to my code after a few weeks and have changed my previous emulator. Now whenever i try sending an email, im getting that infamous 'No applications can perform this action' message.

I have logged into my GMail account through the emulator browser but have not be able to download the GMail app from the google play store (I currently receieve a message telling me I havent accessed the google play soptre before).

Here is my email intent:

public void onClick(View sendEmailClick) {

    emailAdd = setEmailAddress.getText().toString();
    emailSub = setEmailSubject.getText().toString();
    emailMess = setEmailMessage.getText().toString();

    Intent sendEmailIntent = new Intent(Intent.ACTION_SEND); 
    sendEmailIntent.setType("message/rfc822");
       sendEmailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {emailAdd});  
       sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSub); 
       sendEmailIntent.putExtra(Intent.EXTRA_TEXT, emailMess); 
       startActivity(Intent.createChooser(sendEmailIntent, "Send mail..."));
       finish();

}

This is a very frustrating problem as as stated, I have had this code working working before. Do I have to install the GMail app?

Try Using following code

Intent sendEmailIntent = new Intent(android.content.Intent.ACTION_SEND); 
sendEmailIntent.setType("text/html");
   sendEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {emailAdd});  
   sendEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, emailSub); 
   sendEmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailMess); 
   startActivity(Intent.createChooser(sendEmailIntent, "Send mail..."));

For anyone else who is getting this error:

  • Click Settings > Accounts & Sync > Add Account.
  • Enter your Gmail username and password.
  • Click next.
  • Set your server to m.google.com.
  • Click next and that is it.

Your app should now detect Gmail as a relevant email app to send your email intent.

There should be an email app in installed in the emulator.
eg: Gmail.
Try this code:

        Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { "xxx@gmail.com" });
    i.putExtra(Intent.EXTRA_SUBJECT, "Title");
    String message = "Message";
    i.putExtra(Intent.EXTRA_TEXT, message);
    try {
        startActivity(Intent.createChooser(i, "Title"));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(VtuLifeMainActivity.this,
                "There are no email clients installed.", Toast.LENGTH_SHORT)
                .show();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM