Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

dscoppelletti/android-kotlin-notifications-fcm

 
 

Repository files navigation

EggTimer - Final Code

Solution code for Advanced Android with Kotlin Codelab

Content: http://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-notifications-fcm

Introduction

EggTimer is a timer app for cooking eggs. You can start and stop the timer, choose different cooking intervals..

In this codelab, working from this starter app, you:

  • Add notitications to the eggtimer app.
  • Use channels and importance for the app notifications.
  • Customize and style the notifications.

Pre-requisites

You should be familiar with:

  • Services, AlarmManager, Broadcast Receivers.

Getting Started

  1. Download
  2. Swtich to start branch
  3. Run the app.

Lab path

4. Adding Firebase to your Android project

  1. Create a Firebase project
  2. Register your app with Firebase
  3. Add the Firebase configuration file to your project
  4. Configure your Android project to enable Firebase products

5. Starting with Firebase Cloud Messaging

5.1. Sending FCM notifications to a single device

  1. AndroidManifest.xml
    • Step 3.0 - Uncomment to start the service
  2. EggTimerFragment.kt
    • Step 3.1 - Create a new channel for FCM
  3. MyFirebaseMessagingService.kt
    • Step 3.2 - Log registration token

5.1. Sending FCM Notifications to a Topic

  1. EggTimerFragment.kt
    • Step 3.3 - Subscribe to breakfast topic
    • Step 3.4 - Call subscribe topics on start

6. Sending data with FCM

6.1. Data messages

  1. MyFirebaseMessagingService.kt
    • Step 3.5 - Check messages for data

6.2. Handling messages in the foreground and background

  1. MyFirebaseMessagingService.kt
    • Step 3.6 - check messages for notification and call sendNotification

References