{"id":36977,"date":"2024-11-01T09:53:47","date_gmt":"2024-11-01T09:53:47","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=36977"},"modified":"2024-11-01T11:42:45","modified_gmt":"2024-11-01T11:42:45","slug":"course-on-kotlin-android-app-development-receiving-notifications-sent-from-the-server","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/36977\/","title":{"rendered":"course on Kotlin Android app development, receiving notifications sent from the server"},"content":{"rendered":"<p><body><\/p>\n<p>This course will cover how to receive push notifications from a server in Android apps using Kotlin. Mobile applications often provide users with real-time information, making push notifications play a crucial role in enhancing user experience. Through this course, you will learn how to implement push notifications in Android apps using Firebase Cloud Messaging (FCM).<\/p>\n<h2>1. Introduction to Firebase Cloud Messaging (FCM)<\/h2>\n<p>Firebase Cloud Messaging (FCM) is a service provided by Google that helps app developers send messages to users in real-time. This service is primarily used for sending notifications, and messages can include text, images, videos, and more.<\/p>\n<h3>Main Features of FCM<\/h3>\n<ul>\n<li>Messages can be sent from the server to the client.<\/li>\n<li>Messages can be sent both when users are using the app and when they are not.<\/li>\n<li>Supports topic-based messaging.<\/li>\n<\/ul>\n<h2>2. Project Setup<\/h2>\n<p>Let\u2019s go through the process of creating a new project in Android Studio and setting up FCM.<\/p>\n<h3>2.1 Setting up Firebase Console<\/h3>\n<ol>\n<li>Log in to <a href=\"https:\/\/console.firebase.google.com\/\" target=\"_blank\" rel=\"noopener\">Firebase Console<\/a>.<\/li>\n<li>Create a new project and enter the project name.<\/li>\n<li>Add the app as Android. Enter the package name and add the SHA-1 key.<\/li>\n<li>Download the google-services.json file and add it to the app folder of the Android app.<\/li>\n<\/ol>\n<h3>2.2 Gradle Setup<\/h3>\n<p>Add the necessary dependencies to the app&#8217;s build.gradle file:<\/p>\n<pre><code>dependencies {\n        implementation 'com.google.firebase:firebase-messaging-ktx:23.1.0' \/\/ Check for the latest version\n    }<\/code><\/pre>\n<p>And add the following to the project&#8217;s build.gradle file to apply the Google services plugin:<\/p>\n<pre><code>buildscript {\n        dependencies {\n            classpath 'com.google.gms:google-services:4.3.10'\n        }\n    }<\/code><\/pre>\n<h3>2.3 Manifest Setup<\/h3>\n<p>Set up the FCM service in the AndroidManifest.xml file:<\/p>\n<pre><code>&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    package=\"com.example.myapp\"&gt;\n\n    &lt;application\n        ... &gt;\n\n        &lt;service\n            android:name=\".MyFirebaseMessagingService\"&gt;\n            &lt;intent-filter&gt;\n                &lt;action android:name=\"com.google.firebase.MESSAGING_EVENT\"\/&gt;\n            &lt;\/intent-filter&gt;\n        &lt;\/service&gt;\n\n    &lt;\/application&gt;\n    &lt;\/manifest&gt;<\/code><\/pre>\n<h2>3. Implementing FCM Messaging Service<\/h2>\n<p>Now let&#8217;s implement the MyFirebaseMessagingService class to receive messages via FCM.<\/p>\n<h3>3.1 MyFirebaseMessagingService Class<\/h3>\n<p>To receive push notifications, create the MyFirebaseMessagingService class that inherits from FirebaseMessagingService:<\/p>\n<pre><code>import android.app.NotificationChannel\n    import android.app.NotificationManager\n    import android.content.Context\n    import android.os.Build\n    import android.util.Log\n    import com.google.firebase.messaging.FirebaseMessagingService\n    import com.google.firebase.messaging.RemoteMessage\n\n    class MyFirebaseMessagingService : FirebaseMessagingService() {\n        override fun onMessageReceived(remoteMessage: RemoteMessage) {\n            \/\/ Message receive logic\n            Log.d(\"FCM\", \"From: ${remoteMessage.from}\")\n\n            remoteMessage.notification?.let {\n                sendNotification(it.title, it.body)\n            }\n        }\n\n        private fun sendNotification(title: String?, messageBody: String?) {\n            val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager\n            val channelId = \"default_channel\"\n            val builder = NotificationCompat.Builder(this, channelId)\n                .setSmallIcon(R.drawable.ic_notification)\n                .setContentTitle(title)\n                .setContentText(messageBody)\n                .setPriority(NotificationCompat.PRIORITY_DEFAULT)\n\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {\n                val channel = NotificationChannel(channelId, \"Channel human-readable title\", NotificationManager.IMPORTANCE_DEFAULT)\n                notificationManager.createNotificationChannel(channel)\n            }\n\n            notificationManager.notify(0, builder.build())\n        }\n    }<\/code><\/pre>\n<h2>4. Sending Messages from the Server<\/h2>\n<p>Now let&#8217;s look at how to send messages from the server via FCM. We send a POST request using the FCM API to send messages.<\/p>\n<h3>4.1 Server Code Example<\/h3>\n<p>Below is an example of sending messages to FCM from a server using Node.js:<\/p>\n<pre><code>const express = require('express');\n    const admin = require('firebase-admin');\n\n    const app = express();\n    admin.initializeApp({\n        credential: admin.credential.applicationDefault(),\n        databaseURL: 'https:\/\/<your-firebase-app>.firebaseio.com'\n    });\n\n    app.post('\/send', (req, res) =&gt; {\n        const message = {\n            notification: {\n                title: 'Hello!',\n                body: 'You have received a new message.'\n            },\n            token: '<device_registration_token>'\n        };\n\n        admin.messaging().send(message)\n            .then(response =&gt; {\n                res.send('Successfully sent message: ' + response);\n            })\n            .catch(error =&gt; {\n                console.error('Error sending message:', error);\n                res.status(500).send('Error sending message');\n            });\n    });\n\n    app.listen(3000, () =&gt; {\n        console.log('Server is running on port 3000');\n    });<\/device_registration_token><\/your-firebase-app><\/code><\/pre>\n<h2>5. Testing Push Notification Reception<\/h2>\n<p>After setting up the mobile app and the server, let&#8217;s test the reception of push notifications. Run the app in Android Studio and send a POST request to the server to send a push notification. When the user receives the notification, it should be displayed through the NotificationChannel set in the app.<\/p>\n<h2>6. Optimization and Cautions<\/h2>\n<p>When integrating push notifications into your service, keep the following points in mind:<\/p>\n<ul>\n<li>You need to request permission for users to receive notifications.<\/li>\n<li>You should ensure that the content of push notifications is meaningful and that users do not receive unwanted information.<\/li>\n<li>Be careful with token management (e.g., re-registration) when sending messages.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this course, we explored how to receive push notifications sent from the server to an Android app using Firebase Cloud Messaging (FCM). Utilizing FCM can strengthen communication with users and greatly enhance app usability. Based on what you have learned in this course, try developing more advanced applications.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This course will cover how to receive push notifications from a server in Android apps using Kotlin. Mobile applications often provide users with real-time information, making push notifications play a crucial role in enhancing user experience. Through this course, you will learn how to implement push notifications in Android apps using Firebase Cloud Messaging (FCM). &hellip; <a href=\"https:\/\/atmokpo.com\/w\/36977\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;course on Kotlin Android app development, receiving notifications sent from the server&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[143],"tags":[],"class_list":["post-36977","post","type-post","status-publish","format-standard","hentry","category-kotlin-android-app-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>course on Kotlin Android app development, receiving notifications sent from the server - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/36977\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"course on Kotlin Android app development, receiving notifications sent from the server - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"This course will cover how to receive push notifications from a server in Android apps using Kotlin. Mobile applications often provide users with real-time information, making push notifications play a crucial role in enhancing user experience. Through this course, you will learn how to implement push notifications in Android apps using Firebase Cloud Messaging (FCM). &hellip; \ub354 \ubcf4\uae30 &quot;course on Kotlin Android app development, receiving notifications sent from the server&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/36977\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:53:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:42:45+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/36977\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36977\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"course on Kotlin Android app development, receiving notifications sent from the server\",\"datePublished\":\"2024-11-01T09:53:47+00:00\",\"dateModified\":\"2024-11-01T11:42:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36977\/\"},\"wordCount\":495,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Kotlin Android app development\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/36977\/\",\"url\":\"https:\/\/atmokpo.com\/w\/36977\/\",\"name\":\"course on Kotlin Android app development, receiving notifications sent from the server - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:53:47+00:00\",\"dateModified\":\"2024-11-01T11:42:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/36977\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/36977\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/36977\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"course on Kotlin Android app development, receiving notifications sent from the server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"course on Kotlin Android app development, receiving notifications sent from the server - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/36977\/","og_locale":"ko_KR","og_type":"article","og_title":"course on Kotlin Android app development, receiving notifications sent from the server - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"This course will cover how to receive push notifications from a server in Android apps using Kotlin. Mobile applications often provide users with real-time information, making push notifications play a crucial role in enhancing user experience. Through this course, you will learn how to implement push notifications in Android apps using Firebase Cloud Messaging (FCM). &hellip; \ub354 \ubcf4\uae30 \"course on Kotlin Android app development, receiving notifications sent from the server\"","og_url":"https:\/\/atmokpo.com\/w\/36977\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:53:47+00:00","article_modified_time":"2024-11-01T11:42:45+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/36977\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/36977\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"course on Kotlin Android app development, receiving notifications sent from the server","datePublished":"2024-11-01T09:53:47+00:00","dateModified":"2024-11-01T11:42:45+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/36977\/"},"wordCount":495,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Kotlin Android app development"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/36977\/","url":"https:\/\/atmokpo.com\/w\/36977\/","name":"course on Kotlin Android app development, receiving notifications sent from the server - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:53:47+00:00","dateModified":"2024-11-01T11:42:45+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/36977\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/36977\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/36977\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"course on Kotlin Android app development, receiving notifications sent from the server"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=36977"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36977\/revisions"}],"predecessor-version":[{"id":36978,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/36977\/revisions\/36978"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=36977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=36977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=36977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}