26360

How do I detect if an email client is configured on an Android device?

Question:

How do I detect if an email client is configured on an Android device? If no email account is configured Android treats it as text message (I use android.content.Intent.ACTION_SEND). I want to prompt the user that no email client is configured.

Answer1:

Instead of prompting the user that no email client is configured, consider wrapping the ACTION_SEND intent in a chooser via <a href="http://developer.android.com/reference/android/content/Intent.html#createChooser%28android.content.Intent,%20java.lang.CharSequence%29" rel="nofollow">createChooser()</a>. createChooser() will return the intent that the user picked. If the user did not pick a valid email client, you can perhaps pop up an error message or provide the user with the settings screen to declare a valid email client.

Note that it is not possible to determine whether a sending application is a valid "email" application, just whether it is an application for sending. This is why the chooser should be used, so that the user will be the one to realize that they do not have an email client set up. Also note that it is extremely rare for a user to have no email client, as they must at least register with their google account when they start their phone (giving them access to gmail).

Here's an example for sending an email with a chooser:

sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("application/octet-stream"); sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {"myuser@gmail.com"}); sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject"); sendIntent.putExtra(Intent.EXTRA_TEXT, "Body text of email message"); startActivity(Intent.createChooser(sendIntent, "Send Mail"));

Recommend

  • counting number of elements from XML using xpath
  • how to reduce png image filesize in PIL
  • Php ajax multiple file upload with new array
  • Converting a string to dictionary in python
  • Hortonworks shc unresolved dependencies
  • Springboot v2.0.0.M6 WebClient making multiple duplicate HTTP POST calls
  • Access Database LIMIT keyword
  • Efficient custom ordering in Julia DataFrames?
  • Can i use fabric.js and three.js in the same canvas?
  • Issue with $mail->Body in the PHPMailer
  • Print PDF file and Doc file using C#
  • Saving Tuples as blob data types in Sqlite3 in Python
  • Question mark placeholder
  • Saved Core Data does not persist after app closes 80% of the time
  • Jaccard Similarity of an RDD with the help of Spark and Scala without Cartesian?
  • In an Outlook addin, how to check whether we are in compose mode or read mode?
  • Can you manually set Tensorflow LSTM weights?
  • Giving a model knowledge of a many-to-many related model in django
  • Java Arithmetic division
  • Constructor-Prototype cyclic reference JavaScript
  • Cannot get Django 1.7 Migrations to detect proper changes to my DB.
  • iterating through image folder using javascript and adding the result in HTML
  • Accessing parent namespace inside a Shiny Module
  • Getting specific color for specific value using JSON data
  • remove date from DateTimePicker for Compact Framework
  • iPhone SDK Add Image to the Body of an Email?
  • JQuery Validate plugin submitting when it shouldn't
  • Is there a way to run c# forms application without showing a gui window (like a console application)
  • Send HTML Mail with Unicode
  • Generate a runnable jar and include libraries in it with Maven
  • Test for NULLs in multiple columns in MySQL
  • separate tokens in batch file
  • Can I read another applications memory?
  • Cross compile glibc for arm, got undefined reference to some unwind functions
  • How do I use TagLib-Sharp to write custom (PRIV) ID3 frames?
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • JavaScript RegExp Replace