0% found this document useful (0 votes)
3 views2 pages

Email Program

The document contains an XML layout for an Android application with a vertical LinearLayout that includes three EditText fields for email, subject, and message, along with a Send button. The MainActivity Java class initializes these UI components and sets an OnClickListener for the Send button to create an email intent with the provided input. The intent is configured to send an email using the user's email client.

Uploaded by

komalsawant765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Email Program

The document contains an XML layout for an Android application with a vertical LinearLayout that includes three EditText fields for email, subject, and message, along with a Send button. The MainActivity Java class initializes these UI components and sets an OnClickListener for the Send button to create an email intent with the provided input. The intent is configured to send an email using the user's email client.

Uploaded by

komalsawant765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

activity_main.

xml

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

Android:orientation=”vertical” android:layout_width=”match_parent”

Android:layout_height=”match_parent” android:padding=”20dp”>

<EditText android:id=”@+id/toEmail” android:hint=”To Email”

Android:layout_width=”match_parent” android:layout_height=”wrap_content”/>

<EditText android:id=”@+id/subject” android:hint=”Subject”

Android:layout_width=”match_parent” android:layout_height=”wrap_content”/>

<EditText android:id=”@+id/message” android:hint=”Message”

Android:layout_width=”match_parent” android:layout_height=”wrap_content”/>

<Button android:id=”@+id/sendBtn” android:text=”Send”

Android:layout_width=”match_parent” android:layout_height=”wrap_content”/>

</LinearLayout>

Mainactivity.java

Public class MainActivity extends AppCompatActivity {


Protected void onCreate(Bundle savedInstanceState) {

Super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

EditText to = findViewById(R.id.toEmail);

EditText subject = findViewById(R.id.subject);

EditText message = findViewById(R.id.message);

Button send = findViewById(R.id.sendBtn);

Send.setOnClickListener(v -> {

String email = to.getText().toString();

String sub = subject.getText().toString();

String msg = message.getText().toString();

Intent intent = new Intent(Intent.ACTION_SENDTO);

Intent.setData(Uri.parse(mailto: + email));

Intent.putExtra(Intent.EXTRA_SUBJECT, sub);

Intent.putExtra(Intent.EXTRA_TEXT, msg);

startActivity(intent);

});

You might also like