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

Кашина_РМП_ЛБ16

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

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

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

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

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

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

Лабораторная работа № 16

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

на тему: «Облачное мобильное приложение»

Выполнил

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

Кашина Д. А.

Принял

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

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

Цель работы: научится создавать облачные мобильные приложения в Android Studio.

Задание: создать простейшее облачное мобильное приложение, используя Firebase и Android Studio.

Ход работы:

Разметка activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <Button android:id="@+id/btnGetToken" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Получить токен" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Кашина Диана ИПсп-123" app:layout_constraintBottom_toTopOf="@+id/btnGetToken" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.5" /> </androidx.constraintlayout.widget.ConstraintLayout>

Код программы – MainActivity.java и MyFirebaseMessagingService.java

package com.example.kashinaaplication16; import android.os.Bundle; import android.util.Log; import android.widget.Button; import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.google.firebase.messaging.FirebaseMessaging; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); Button btn = findViewById(R.id.btnGetToken); btn.setOnClickListener(v -> { FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> { if (!task.isSuccessful()) { Log.w("App", "Ошибка получения токена", task.getException()); Toast.makeText(MainActivity.this, "Ошибка!", Toast.LENGTH_SHORT).show(); return; } String tkn = task.getResult(); Toast.makeText(MainActivity.this, "Token: " + tkn, Toast.LENGTH_LONG).show(); Log.d("App", "Token [" + tkn + "]"); }); }); } }

package com.example.kashinaaplication16; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Build; import android.util.Log; import androidx.core.app.NotificationCompat; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); Log.d("Msg", "Сообщение получено: " + remoteMessage.getData()); if (remoteMessage.getNotification() != null) { sendNotification(remoteMessage.getNotification().getBody()); } } @Override public void onNewToken(String token) { Log.d("Not", "Новый токен: " + token); } private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); String channelId = "fcm_default_channel"; NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, "Уведомления", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(android.R.drawable.ic_dialog_info) .setContentTitle("Message") .setContentText(messageBody) .setAutoCancel(true) .setContentIntent(pendingIntent); notificationManager.notify(1410, notificationBuilder.build()); } }

файл google-services.json

{ "project_info": { "project_number": "646218320744", "project_id": "aplication16-f69ca", "storage_bucket": "aplication16-f69ca.firebasestorage.app" }, "client": [ { "client_info": { "mobilesdk_app_id": "1:646218320744:android:45c607967ce07d858464dd", "android_client_info": { "package_name": "com.example.kashinaaplication16" } }, "oauth_client": [], "api_key": [ { "current_key": "AIzaSyBhoDUPB4j7CLUVpMmmG3RU1iopUVtJ_jM" } ], "services": { "appinvite_service": { "other_platform_oauth_client": [] } } } ], "configuration_version": "1" }

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

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