Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Кашина_РМП_ЛБ15_4

.docx
Скачиваний:
0
Добавлен:
22.09.2026
Размер:
72 Кб
Скачать
☆

Министерство науки и высшего образования Российской Федерации Федеральное государственное бюджетное образовательное учреждение высшего образования

«Владимирский государственный университет

имени Александра Григорьевича и Николая Григорьевича Столетовых» (ВлГУ)

Колледж инновационных технологий и предпринимательства

КАФЕДРА ФИЗИКИ И ПРИКЛАДНОЙ МАТЕМАТИКИ

Лабораторная работа № 15_4

по МДК 01.03 «Разработка мобильных приложений»

на тему: «Почтовые клиенты в Андроид»

Выполнил

студент группы ИПсп-123

Кашина Д. А.

Принял

Красильщикова В.В.

Владимир, 2026 г.

Цель работы: получить практические навыки работы с почтовыми клиентами в AndroidStudio.

Ход работы:

ActivityMain.java

package com.example.laba15_4; 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 { private EditText etTo, etSubject, etMessage; private Button btnSend; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Инициализация элементов etTo = findViewById(R.id.etTo); etSubject = findViewById(R.id.etSubject); etMessage = findViewById(R.id.etMessage); btnSend = findViewById(R.id.btnSend); // Обработчик кнопки btnSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendEmail(); } }); } private void sendEmail() { // Получаем введенные данные String to = etTo.getText().toString().trim(); String subject = etSubject.getText().toString().trim(); String message = etMessage.getText().toString().trim(); // Проверка на пустые поля if (to.isEmpty()) { Toast.makeText(this, "Введите email получателя", Toast.LENGTH_SHORT).show(); return; } if (subject.isEmpty()) { Toast.makeText(this, "Введите тему письма", Toast.LENGTH_SHORT).show(); return; } if (message.isEmpty()) { Toast.makeText(this, "Введите сообщение", Toast.LENGTH_SHORT).show(); return; } // Создаем Intent для отправки письма Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{to}); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, message); // Устанавливаем MIME тип для почты intent.setType("message/rfc822"); // Запускаем выбор почтового приложения try { startActivity(Intent.createChooser(intent, "Выберите почтовое приложение")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(this, "На устройстве не установлен почтовый клиент", Toast.LENGTH_SHORT).show(); } } }

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp" tools:context=".MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Почтовый клиент" android:textSize="24sp" android:textStyle="bold" android:gravity="center" android:layout_marginBottom="24dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Кому:" android:textSize="18sp" android:layout_marginBottom="8dp" /> <EditText android:id="@+id/etTo" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="email@example.com" android:inputType="textEmailAddress" android:padding="12dp" android:background="@android:drawable/editbox_background" android:layout_marginBottom="16dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Тема:" android:textSize="18sp" android:layout_marginBottom="8dp" /> <EditText android:id="@+id/etSubject" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Тема письма" android:padding="12dp" android:background="@android:drawable/editbox_background" android:layout_marginBottom="16dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Сообщение:" android:textSize="18sp" android:layout_marginBottom="8dp" /> <EditText android:id="@+id/etMessage" android:layout_width="match_parent" android:layout_height="150dp" android:hint="Текст сообщения" android:padding="12dp" android:background="@android:drawable/editbox_background" android:gravity="top" android:layout_marginBottom="24dp" /> <Button android:id="@+id/btnSend" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Отправить" android:textSize="18sp" android:padding="12dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Автор: Кашина Д. А.\nГруппа: ИПсп-123" android:textSize="14sp" android:gravity="center" android:layout_marginTop="24dp" android:textColor="#666666" /> </LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.laba15_4"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="Почтовый клиент" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- Добавляем фильтр для приема SEND интентов --> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="message/rfc822" /> </intent-filter> </activity> </application> </manifest>

Результат работы программы:

Вывод: в ходе выполнения лабораторной работы были получены практические навыки работы с почтовыми клиентами в AndroidStudio.