Android Email

less than 1 minute read

AndroidManifest.xml


MainActivity.java

    /**
     * Send email
     */
    public void SendToEmail(Context context, String recipient) {

        String[] recipients = { recipient };

        Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));

        // prompts email clients only

        email.setType("message/rfc822");
        email.putExtra(Intent.EXTRA_EMAIL, recipients);

        try {
            // the user can choose the email client
            context.startActivity(Intent.createChooser(email, "Email : " + recipient));

        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(context, context.getResources().getString(R.string.msg_no_email), Toast.LENGTH_LONG).show();
        }
    }

Tags:

Categories:

Updated:

Leave a comment