Email activity on Android

2020-05-07 05:15发布

问题:

I want to send email from Android virtual machine to my gmail account. Problem: but on pressing send button I am getting:

"No application can perform this action"

Here is my code:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("audio/mp3");
//sendIntent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/download/test.mp3")); 
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(GlobalVariable.getstrEmail())); 
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(sendIntent, "Title:"));

回答1:

Try it on a real device itself, it should work. And you need to change the type:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email@example.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));


回答2:

This can help...

  Intent openEmailIntent = new Intent(android.content.Intent.ACTION_SEND);
  openEmailIntent.setType("plain/text");
  openEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                           new String[{"zoombie@gmail.com"});
  openEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"subject you want");
  openEmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Any body ");
  this.startActivity(Intent.createChooser(openEmailIntent,"Sharing via Email"));


回答3:

try this....

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);        
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{emailaddress});                                        
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));