0% found this document useful (0 votes)
22 views3 pages

Practical 30

The document provides code for an Android application that allows sending emails. It includes XML layout files for the user interface, Java code for the main activity class, and a manifest file. The application allows users to enter a recipient, subject, and message and then sends an email with that information when a send button is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Practical 30

The document provides code for an Android application that allows sending emails. It includes XML layout files for the user interface, Java code for the main activity class, and a manifest file. The application allows users to enter a recipient, subject, and message and then sends an email with that information when a send button is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

MAD CO6I Practical 30

Name: Pranjal Shahane Roll No: 06


Practical: 30

Q1. Write a program to send a email.


CODE:
Activity.xml android:id="@+id/sendButton"
android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?> android:layout_height="wrap_content"
<RelativeLayout
xmlns:android="http://schemas.android.com/ android:layout_below="@id/messageEditText
apk/res/android" "
android:layout_marginTop="16dp"
xmlns:tools="http://schemas.android.com/to android:text="Send Email" />
ols"
android:layout_width="match_parent" </RelativeLayout>
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity"> Main_activity.java
<EditText package com.example.practical;
android:id="@+id/recipientEditText"
android:layout_width="match_parent" import android.content.Intent;
android:layout_height="wrap_content" import android.net.Uri;
android:hint="Recipient Email" /> import android.os.Bundle;
import android.view.View;
<EditText import android.widget.Button;
android:id="@+id/subjectEditText" import android.widget.EditText;
android:layout_width="match_parent" import android.widget.Toast;
android:layout_height="wrap_content" import
androidx.appcompat.app.AppCompatActivity;
android:layout_below="@id/recipientEditText
" public class MainActivity extends
android:layout_marginTop="16dp" AppCompatActivity {
android:hint="Subject" />
EditText recipientEditText, subjectEditText,
<EditText messageEditText;
android:id="@+id/messageEditText" Button sendButton;
android:layout_width="match_parent"
android:layout_height="wrap_content" @Override
protected void onCreate(Bundle
android:layout_below="@id/subjectEditText" savedInstanceState) {
android:layout_marginTop="16dp" super.onCreate(savedInstanceState);
android:hint="Message" /> setContentView(R.layout.activity_main);

<Button recipientEditText =

Gramin Technical & managemnet campus 1


MAD CO6I Practical 30

findViewById(R.id.recipientEditText); Toast.makeText(MainActivity.this,
subjectEditText = "There are no email clients installed.",
findViewById(R.id.subjectEditText); Toast.LENGTH_SHORT).show();
messageEditText = }
findViewById(R.id.messageEditText); }
sendButton = }
findViewById(R.id.sendButton);

sendButton.setOnClickListener(new
View.OnClickListener() {
Manifest.xml
@Override <?xml version="1.0" encoding="utf-8"?>
public void onClick(View v) { <manifest
String recipient = xmlns:android="http://schemas.android.com/
recipientEditText.getText().toString(); apk/res/android"
String subject =
subjectEditText.getText().toString(); xmlns:tools="http://schemas.android.com/to
String message = ols">
messageEditText.getText().toString(); <uses-permission
android:name="android.permission.SEND_SM
if (!recipient.isEmpty() && ! S"/>
subject.isEmpty() && !message.isEmpty()) { <uses-permission
sendEmail(recipient, subject, android:name="android.permission.READ_PH
message); ONE_STATE"/>
} else {
Toast.makeText(MainActivity.this, <application
"Please enter recipient, subject, and android:allowBackup="true"
message", Toast.LENGTH_SHORT).show();
} android:dataExtractionRules="@xml/data_ext
} raction_rules"
});
} android:fullBackupContent="@xml/backup_ru
les"
private void sendEmail(String recipient, android:icon="@mipmap/ic_launcher"
String subject, String message) { android:label="@string/app_name"
Intent intent = new
Intent(Intent.ACTION_SEND); android:roundIcon="@mipmap/ic_launcher_r
intent.setType("message/rfc822"); ound"
intent.putExtra(Intent.EXTRA_EMAIL, android:supportsRtl="true"
new String[]{recipient}); android:theme="@style/Theme.Practical"
intent.putExtra(Intent.EXTRA_SUBJECT, tools:targetApi="31">
subject); <activity
intent.putExtra(Intent.EXTRA_TEXT, android:name=".MainActivity"
message); android:exported="true">
<intent-filter>
try { <action
android:name="android.intent.action.MAIN" /
startActivity(Intent.createChooser(intent, >
"Send email..."));
} catch <category
(android.content.ActivityNotFoundException android:name="android.intent.category.LAUN
ex) {

Gramin Technical & managemnet campus 2


MAD CO6I Practical 30

CHER" /> </application>


</intent-filter>
</activity> </manifest>

OUTPUT:

Gramin Technical & managemnet campus 3

You might also like