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