If you want to launch an email client (composing a new email), you can use the power of Intents to achieve that. The email client can be launched by pre filling the certain details like to address, subject, body and optional attachment.

Typically this will be used in the app, when you want to provide email support. The function below also attaches device information like OS version, device manufacturer and other useful device information to provide further support.

    public static void contactHelpAndSupport(Context context, String[] to, String subject) {
        String body = "";
        try {
            body = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
            body = "How can we help?\n\n\n\n\n\n\nPlease do not delete below contents\nDevice OS: Android(" +
                    Build.VERSION.RELEASE + ")\n App v" + body + "\n Device: " + Build.BRAND +
                    ", " + Build.MODEL;
        } catch (PackageManager.NameNotFoundException e) {
        }
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL, to);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, body);
        context.startActivity(Intent.createChooser(intent, "Send email:"));
    }

Here is the full code snippet to call the email client.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // pass array of to email ids
        contactHelpAndSupport(this, new String[]{"contact@androidhive.info", "admin@androidhive.info"}, "App help & support");
    }

    public static void contactHelpAndSupport(Context context, String[] to, String subject) {
        String body = "";
        try {
            body = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
            body = "How can we help?\n\n\n\n\n\n\nPlease do not delete below contents\nDevice OS: Android(" +
                    Build.VERSION.RELEASE + ")\n App v" + body + "\n Device: " + Build.BRAND +
                    ", " + Build.MODEL;
        } catch (PackageManager.NameNotFoundException e) {
        }
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL, to);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, body);
        context.startActivity(Intent.createChooser(intent, "Send email:"));
    }
}
Author

Ravi is hardcore Android programmer and Android programming has been his passion since he compiled his first hello-world program. Solving real problems of Android developers through tutorials has always been interesting part for him.

  • Is There any tips that how to make android app of YouTube channel

  • Pradum Gupta

    i need your android studio… to design my application… bcz my android studio is not working…
    cn you give me

    • Why it’s not working? Is there any error, which platform you are trying it on?

      • Pradum Gupta

        My gradle is not opening . Thts why i m able to create any app

        • Try downloading latest version of Android Studio.
          https://developer.android.com/studio/index.html

          • Pradum Gupta

            Not working

          • Pradum Gupta

            What to do now… cn you give me your studio

          • Dude thats not how you solve the issue. My Android Studio is same as the one from the link I have sent. You need to identify the problem / error. Without any error report I can’t help you much.

          • Pradum Gupta

            can you tell how to add support.v7.AppCompactActivity
            and how to download gradle 4.0 and support v7

          • Could you record your screen and upload the video to Android Studio. I can help.