简体   繁体   中英

Sending email from android app

I need to provide feature for users where users can share some data by sending email. I used below code.

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "testing email send.");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<b>this is html text in email body.</b>"));
startActivity(Intent.createChooser(emailIntent, "Email to Friend"));

This shows mail app, gmail and bluetooth for user to choose. I dont want user to show bluetooth in this list. What i need to do ? I have facebook app, which does same thing, but doesn't show bluetooth in the list. I need to do the same.

You can use the ACTION_SENTTO instead of ACTION_SEND to get the list of e-mail clients. I tried this on HTC Wildfire which had default e-mail client, GMail app and k9-3.508-release installed. When I ran your code with ACTION_SENDTO, I got list of above mentions 3 e-mail clients and not bluetooth no matter if bluetooth was enabled or disabled. I tried it both when the bluetooth was enabled and when bluetooth was disabled. It worked well for me.

Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "testing email send.");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<b>this is html text in email body.</b>"));
startActivity(Intent.createChooser(emailIntent, "Email to Friend"));

请尝试使用此类型:

emailIntent.setType("message/rfc822");

Try adding the EXTRA_EMAIL to your intent, maybe bluetooth can be connected to ACTION_SEND but not to the same action if an email is to be send.

See here:
http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND and here
http://developer.android.com/reference/android/content/Intent.html#EXTRA_EMAIL

Just a rough guess ...

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