Email App
1. Creating “Emailapp” Application.
1. Click Start →Android Studio, a Welcome to Android Studio dialog box will appear.Click New Project, the New
Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly
Bean”, Android 4.1). Click Finish Button.
4. Create a Button resource in activity_main.xml and update the following code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<EditText
android:id="@+id/subject"
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="Enter Subject" />
<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="@+id/content1"
android:hint="Enter Content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="@+id/email"
android:hint="email"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnSend"
android:text="Send Email"/>
</LinearLayout>
5. Create a Button object, create clickListener, onClick event and update the following code in MainActivity.java.
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
EditText Editsubject,Editcontent,Editemail;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.btnSend);
Editsubject = findViewById(R.id.subject);
Editcontent = findViewById(R.id.content1);
Editemail = findViewById(R.id.email);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String subject,content,email;
subject = Editsubject.getText().toString();
content = Editcontent.getText().toString();
email = Editemail.getText().toString();
if(subject.equals("") && content.equals("") && email.equals("")){
Toast.makeText(MainActivity.this, "All fields are required", Toast.LENGTH_SHORT).show();
}else {
sendEmail(subject,content,email);
});
public void sendEmail(String Editsubject,String Editcontent, String email){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(Intent.EXTRA_SUBJECT, Editsubject);
intent.putExtra(Intent.EXTRA_TEXT,Editcontent);
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent,"Choose email client"));