0% found this document useful (0 votes)
10 views4 pages

Ex 30

The document provides code snippets for an Android application that allows users to send emails. It includes the XML layout for the user interface and the Java code for the MainActivity, which handles user input and email sending functionality. Key components include EditText fields for email, subject, and message, along with a button to initiate the email sending process.
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)
10 views4 pages

Ex 30

The document provides code snippets for an Android application that allows users to send emails. It includes the XML layout for the user interface and the Java code for the MainActivity, which handles user input and email sending functionality. Key components include EditText fields for email, subject, and message, along with a button to initiate the email sending process.
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/ 4

X.

Exercise
1. Write a program to send email.

activity_main.xml android:layout_height="wrap_content"
android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?> android:gravity="center"
<LinearLayout android:hint="Email Id"
xmlns:android="http://schemas.android.com/apk/r
android:textSize="16sp"
es/android"
tools:ignore="InvalidId" />
xmlns:app="http://schemas.android.com/apk/res-
auto"
<EditText
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/etsubject"
android:layout_width="match_parent"
android:layout_width="411dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
android:hint="Subject"
android:textSize="16sp"
<Space
tools:ignore="InvalidId" />
android:layout_width="match_parent"
android:layout_height="34dp" />
<EditText
android:id="@+id/etmsg"
<TextView
android:layout_width="match_parent"
android:id="@+id/textView"
android:layout_height="208dp"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="46dp"
android:gravity="center"
android:text="Email App"
android:hint="Message"
android:textAlignment="center"
android:textSize="16sp"
android:textColor="#000000"
tools:ignore="InvalidId" />
android:textSize="20sp" />

<Button
<EditText
android:id="@+id/btnsend"
android:id="@+id/etmail"
android:layout_width="wrap_content"
android:layout_width="411dp"
android:layout_height="60dp"
android:text="Send" String id=et1.getText().toString();
android:textSize="16sp" /> String subject=et2.getText().toString();
</LinearLayout> String message=et3.getText().toString();
Intent mail=new
Intent(Intent.ACTION_SEND);
MainActivity.java

mail.putExtra(Intent.EXTRA_EMAIL,id);
package com.example.ex3001;
mail.putExtra(Intent.EXTRA_SUBJECT,subject);

import
androidx.appcompat.app.AppCompatActivity; mail.putExtra(Intent.EXTRA_TEXT,message);

import android.content.Intent; mail.setType("Message/rfc812");

import android.view.View;
startActivity(Intent.createChooser(mail,"Send"));
import android.widget.Button;
}
import android.widget.EditText;
});
import android.os.Bundle;
}
}
public class MainActivity extends
AppCompatActivity {

EditText et1,et2,et3;
Button btn1;

@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etmail);
et2=findViewById(R.id.etsubject);
et3=findViewById(R.id.etmsg);
btn1=findViewById(R.id.btnsend);
btn1.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View view) {
Output:

You might also like