12788

How to send an email in android 2.2?

Question:

I want to send an email with android 2.2. First I made an intent chooser with an ACTION_SEND to select which to use :

Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, Resources.getString("EmailInvitationSubject", getBaseContext())); String body = Resources.getString("EmailInvitationBody", getBaseContext()) + Local.User.FirstName; intent.putExtra(Intent.EXTRA_TEXT, body); startActivity(Intent.createChooser(intent, "Invite friends"));

But in that case, the selector show 'Bluetooth, Messaging, Google+, Gmail'. I want to show ONLY Gmail or other email app.

I saw in the sdk docs there's a new CATEGORY_APP_EMAIL to use but it's only available in the API level 15. I have to keep API level 8. Is there a way to do that ?

By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: one for email and one for messaging.

Answer1:

This code will shows only the email clients,

Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail@yahoo.com"}); email.putExtra(Intent.EXTRA_SUBJECT, "subject"); email.putExtra(Intent.EXTRA_TEXT, "message"); email.setType("message/rfc822"); startActivity(Intent.createChooser(email, "Choose an Email client :"));

Answer2:

You might want to checkout following (to get what you are looking at the end, i.e. "....By the way, I'll want to do it for messaging too so that in the end I can have 2 buttons: "): <a href="http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android" rel="nofollow">http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android</a>

or also you could checkout: <a href="https://stackoverflow.com/questions/3979226/android-email-chooser" rel="nofollow">Android email chooser</a>

Kind regards,<br /> Bo

Recommend

  • I tried using this Flag in setFlags from tutorial but its deprecated, what do i do
  • Unable to send email with attachments from my app using intents (Gmail)
  • openerp Message_post error..NameError: global name '_' is not defined
  • Google Contacts API asp.net settings and authorization token
  • Retrieve google contact based on contact Id
  • How do I chomp a string if I have Perl 4?
  • How can I send mail from my app with underline or bold text?
  • Vim folding : how to hide all the single lines not containing a search pattern (or fold zero line)?
  • How to move again MainActivity after sending the mail?
  • LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary`2[System.
  • Sending email using standard gmail app without chooser
  • Get current user from inside the model in Sails
  • Send data from edittext to listview
  • Splash Screen will not display
  • How can go in last activity with resume button?
  • Android Google Maps API v2 start navigation
  • saving file generated by TCPDF
  • How to use JavaScript to determine whether a file exists in a directory?
  • ADO and msqli connections very slow
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • PHP buffered output depending on server setting?
  • Play WS (2.2.1): post/put large request
  • Bad request using file_get_contents for PUT request in PHP
  • Dialing with Intent.ACTION_CALL stopps at # in phone number
  • Dynamically accessing properties of knockoutjs observable array
  • How to set my toolbar fixed while scrolling android
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • AT Commands to Send SMS not working in Windows 8.1
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Turn off referential integrity in Derby? is it possible?
  • Authorize attributes not working in MVC 4
  • apache spark aggregate function using min value
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Busy indicator not showing up in wpf window [duplicate]
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • How to Embed XSL into XML
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF