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

Practical No 30 Email

The document contains code for an Android application that allows users to send emails through a simple user interface. It includes an XML layout file with three EditText fields for the recipient, subject, and message, and a Button to send the email. The MainActivity.java file handles the button click event to create an email intent and launch the email client with the provided information.

Uploaded by

Samiksha Bhosale
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)
18 views2 pages

Practical No 30 Email

The document contains code for an Android application that allows users to send emails through a simple user interface. It includes an XML layout file with three EditText fields for the recipient, subject, and message, and a Button to send the email. The MainActivity.java file handles the button click event to create an email intent and launch the email client with the provided information.

Uploaded by

Samiksha Bhosale
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

Practical no 30

Activity_main.xml

<?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:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et1"
android:hint="To "/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et2"
android:hint="Subject: "/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et3"
android:hint="Message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEND"
android:id="@+id/bt1"/>
</LinearLayout>

AndroidMenifest.xml

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="message/rfc822"/>
</intent-filter>

MainActivity.java

package com.example.email;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText e1=(EditText) findViewById(R.id.et1);
EditText e2=(EditText) findViewById(R.id.et2);
EditText e3=(EditText) findViewById(R.id.et3);
Button b1=(Button) findViewById(R.id.bt1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL,new String[]{e1.getText().toString()});
i.putExtra(Intent.EXTRA_SUBJECT,e2.getText().toString());
i.putExtra(Intent.EXTRA_TEXT,e3.getText().toString());
i.setType("message/rfc822");
startActivity(Intent.createChooser(i,"Choose Mail App"));
}
});
}
}

Output:

You might also like