package com.example.emailapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    Button btnSend;
    EditText To;
    EditText Subject;
    EditText Message;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);   
        
        To = (EditText) findViewById(R.id.etTO);
        Subject = (EditText) findViewById(R.id.etSubject);
        Message = (EditText) findViewById(R.id.etMsg);
        btnSend = (Button) findViewById(R.id.send_email_button);
        
        btnSend.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
              String to = To.getText().toString();
              String subject = Subject.getText().toString();
              String message = Message.getText().toString();
              
              Intent email = new Intent(Intent.ACTION_SEND);
              email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});
              email.putExtra(Intent.EXTRA_SUBJECT, subject);
              email.putExtra(Intent.EXTRA_TEXT, message);          
              email.setType("message/rfc822");              
              startActivity(Intent.createChooser(email, "Select Email Client"));
              
            }
        });
    }
}