Android + Firebase Cloud Messaging - Complete Course | Stevdza - San | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Android + Firebase Cloud Messaging - Complete Course

teacher avatar Stevdza - San, Android Developer & UX/UI Designer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

15 Lessons (1h 15m)
    • 1. Introduction

    • 2. Notification Overview

    • 3. Notification Channel

    • 4. Notification Posting Limits

    • 5. Create Basic Notification

    • 6. Create Expandable Notification

    • 7. Add Notification Action Button

    • 8. Create Custom Notification

    • 9. Introducing to Firebase Cloud Messaging

    • 10. Connect Android App to Firebase

    • 11. Send Message to Single Device

    • 12. Send Message to Multiple Devices

    • 13. Send Image Payload

    • 14. Send Data Payload

    • 15. Light, Sound and Vibration

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

In this course you are going to learn everything you need to successfully implement Firebase Cloud Messaging API, create Push Notifications and target single/multiple users in your application. We are going to use Google Firebase Console (Notification Composer) to actualy design and send our message to Android App. Then in Android App we are going to create a Service, which will trigger notification when we receive a message from Firebase. Learning with me, you will realise how easy it will be to implement this.

Also you are going to learn everything about Notifications in Android: Anatomy, Usage, Limits, Different Styles, Custom Notification Layouts, Images, Text, Action Buttons, Intents, Notification Channels, Vibration, Light, Sound and more.

Cloud Messaging is a MUST if you are planning to develop Modern Application.

Meet Your Teacher

Teacher Profile Image

Stevdza - San

Android Developer & UX/UI Designer


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: Ah, hello there. And welcome to my course. In these scores, you're going to learn everything you need to successfully implement Firebase cloud messaging, FBI create push notifications and the target single or multiple users in your application we're going to. It was a Google firebase console, specifically notification composer toe actually design and send our message toe Android application. Then in enjoyed app, we're going to create a service which will trigger notification. When we received a message from Firebase, I'm going to start this course by introducing you to notifications in Android. You're going to learn everything about notifications such as a notification anatomy, notification, usage limits, different styles, custom notification layouts, adding images, text extra buttons creating intense notification channels. Setting sound and vibration will win Trigger notification. Using led is to notify users about you notifications and more. Also, after we learn everything about medications, we real proceed next, where we are going to connect our application Fire base and the implement Firebase cloud messaging AP I where we will be able to receive notifications even from a background and when our application is no longer active or focused. So every modern application is now using the cloud messaging toe communicate with its users by occasionally sending this counts, updates, news and other relevant information. That's a huge advantage because we, as the developers don't need to update our application every time we want to provide a new information to our users. Instead, we can do that in a just few steps from our fibers console. So what are you waiting for? Enrolling this course today and start learning and improving your skills right away. 2. Notification Overview: notification. A notification is a message that android that this place outside your applications you I to provide the user with the reminders, communication from other people or other timely information from your application. Users can tap the notification toe, open your application or to take an action directly from the notification. Beginning with the android 5.0, notifications can appear on the screen. You can programmatically set a level off details visible in a secure lock screen, or even whether the notification will show on the lock screen at all. Users can use the system settings to choose the level of details visible on the lock screen , including the option to disable a lock screen notifications and starting with the enjoyed 8.0. Users can choose to disable or enable lock screen notifications for each notification channel. And I want to talk about the notification channel in some of the next video because that's ah, very important topic on the design off notification is determined by assistant templates, and your applications simply defines the contents for each portion of the template. So there are six important parts off each identification. There is a small icon, this part is required and you can set the small icon with set small icon method application name. This is provided by the system itself. Timestamp. This is the provided by system, but you can override with set one method. Large icon. This is optional of course. Title. This is optional, and you can said that with set content title method, and the text is, of course, optional. And you can say that with set content text method. Although it's not required, every notification should open an appropriate the application activity went there. In addition to this, the fourth quantification action, you can add the extra buttons that complete an application related desk from the notification, often without opening an activity on from Android 7.0 or FBI Level 24. You can also end an action to reply to a message or enter other text directly from the notification and from enjoy the 10 or a P r Level 29 the platform can automatically generate. The action button switch has suggested intent based the actions 3. Notification Channel: ah, notification shells. So from enjoyed 8.0 or a P A little 26. All notifications must be assigned to a channel, or it will not appear so By categorizing notifications into channels, users can disable specific notification shell for your application, instead off disabling all your notifications. And also users can control the visual and auditory options for each channel or from the enjoyed system settings. User scare. Also a long press notification to change behaviors for The Associated Channel as well. One application can have multiple identification shells separate general for each type of notification. The application issues applications can also create the ratification channels in response to choices made by users off your application. For example, you may set up separate notification channels for each conversation group created by user in a messaging application. So the channel is also where you specify the importance level for your identifications on Enjoyed 8.0, and higher eso all notifications supposedto the same notification channels have the same behavior on Android uses the importance off a notification to determine how much of the notification should interrupt the user visually in the auditory. So the higher the importance off a notification that Mawr interrupted. The notification will be so, Ah, there are four possible importance levels. The 1st 1 is urgent, so it makes a sound and the Pierce is a heads up unification next one below is a high, which makes a sound bellow. Death is a media which makes no sound. And of course, at the bottom we have low, which makes no sound and does not appear in the status bar either. 4. Notification Posting Limits: beginning with enjoyed the 8.1 or FBI Level 27 applications cannot make identifications sound more than once per second. So if your application posts multiple notifications in one second, they all appear as expected, but only the first notification per second makes a sound, however Enjoyed also applies rate limit when updating a notification. So if you post updates to a single notification to frequently, for example, in less than one second, the system might drop some updates. Starting in enjoyed 5.0, or a piano 21 user skin enable Do Not disturb mode, which silences sound and vibration for all notifications. Notification still appears in the system. You. Why is normal unless there was a specifies. Otherwise, there are three different levels available in the do not disturb mode, so the 1st 1 is total silence. It box all sounds and vibrations, including from alarms, music, videos and games. The 2nd 1 is armed only. It blocks all sounds and vibrations except from alarms, and the 3rd 1 is a priority only user skin configure, which sister wife categories can interrupt them, such as all the alarms, reminders, events, cause or messages on the enjoyed 8.0 or F B L M 26 above. User skin additionally allowed notifications through at specific categories, also known as the chills. By overriding, do not disturb on the channel by channel basis. For example, a payment application might have chills for notifications, related toe withdrawal and the deposit. The user can then choose to allow either withdrawal notifications, deposit notifications or both of them when devices running enjoyed 7.1 or April 25 below. User skin. Allow notifications through at by AP basis rather than on channel by channel basis, which means users who have devices with a P 11 26 you have more freedom when it comes to customizing, enabling or disabling application notifications. Eso knowing all those posting limits and the system settings which regular user can choose , is a very important when you're developing an application and you don't want to disturb a user by posting notifications to frequently or otherwise I user might block not just one notification channel for your application by the whole app as well 5. Create Basic Notification: Ah, hello there. And welcome back. So in this video, we're going to start by creating notification into our android applications. So first, we're going to start by creating our layout. So our layout will have only one at a text in the one button. So let's ah, connect those constraints. And basically, what this layout will will do. The first edit text will take in a number input for, for example, the number of cookies and the butler will say bye. So when we click, our button button will trigger the notification, and you will see how our notification will look afterwards. So first here, we're going to add the ideas and we're going toe change the text and the king for our, uh, that it text. So here, for the with, I want to set the match, parent. All right. Okay, so, uh, here inside our main activity class, I'm going toe, create edit text and the button objects. So now we're going to find the idea of those two ah elements, and then we're going to set the click. Listen for our bottom. Where, ah, we're going to trigger the notification. So ah, here, as you can see. Ah, okay, so we need to change this edit text to receive ah, number input. So instead, off this text person, we will try the number. So when we click when our edit text now, it will show us only the numbers. Okay, so basically, we went with the number of cookies we want to buy here. All right, so first, we're going to create Ah, two strings. But before that, let's ah, get a text from this area text, and we're going toe store this text inside our number of cookies string. Okay. So, um, after that, I'm going to create the notification compact, the builder. And here I'm going toe passes the first perimeter main activity and the as a second perimeter, it will be We will provide the channel ity. So this is only required for a compatibility with the enjoyed eight point over and higher. But it is a goal by older versions. So because the channel is only important for ah, android eight point. Oh, and the older versions does not support this channel. So here we passed this gentle lady in our main activity. And of course, I have created a global variable Channel I D. So we can use this generally later in this video. So now we're going to set a small I can hear. But first, let's add one vector file here. So inside our global directory, we're going to create the new vector asset, and we're going to choose the summer vector file from the default enjoyed Studio Repository . So let's choose this. Let's type here chat, for example, and let's choose this one. It's changed the name toe. I see Chet just like that and click. OK, finish. And here we're going toe pass this file vector file. Okay, so our notification should have a smaller Eichel and now we're going to set the content title. So this is the title off our notification. And let's type here, for example. You're just both and the number of cookies a string. So basically, the string will contain the number off off cookies which use Ah, both. So here, down below, it's set the content, that text. So, basically, this is a description for our notification. And let's copy this first string here and the title should say just cookies, so it kind of looks better. All right, so next one is a priority, so as a priority will sell select the full priority. So in most cases, you're going to use this default priority only for ah, most important notifications your gun. It was a higher priority, but for now, for now, it will stay this way. Next women to initialize, Unification manager competent. And here we're going to use this object toe toe. Call this method notify and we're going to pass the first i d one. And of course, we're going to pass a second perimeter, our our vacation compact builder and its method build. All right, so after that, I think we can around our application and check it out. So here, for example, type number 10 and click buy. So as you can see, our notification appeared immediately. So we have a small Iker title and the text and of course, above we can see the name off our application and the time which application appeared on a little vacation appeared. So now that ah, we have ah set up all death we can create now on Notification channel So notification channel is important if you want your application to run on the enjoyed 8.0, in higher. So we're going to say here if build version as the K int Okay, is ah equals or bigger than build the version goads Oh, which is basically for enjoyed eight point. Oh, And here if user is using a device which enjoyed 8.2 or higher, we're going to create a notification child. So first, let's create string for name and description. So named for our channel will be my channel name. This is just an example, and the scripture will say something like my child description. It's that simple. Okay, so you can set the different values here. But this is just an example. And I'm going to add the integer for importance and I want to set the notification manager importance. They fought. So as you can see in our above code for notification company building, we use the notification compact class and its method priority their fourth and this in this created defecation channel. We're going to use a certification manager instead, and its importance default method or constant sort. So next one, we're going to create a notification channel object, and here we're passing the Channel I D, which is the same as from our notification company builder. The name and the importance and the down below. We're going to set description as well. Okay, so, uh, I'm going to add some comments here, so basically, you'll need to create this notification channel only on a PR level 26 which is enjoyed the eight point. Oh. So, uh, with the kid from channel eyes, a new class and ah, does Ah, it's not in support library. And that's why we, uh we're adding this. Okay, So down below, we're going to identification manager, Okay? And here, we're going to use get system service, and we're going to pass certification manager class here. Okay? And now we're going to use this manager object, and we're going to set. Oh, no. So we want to create the notification shell, and we went toe pass our channel object or notification tunnel object. And here basically were Ah, we should have a registered our channel notification channel with the android system. And it is very important to know that you cannot change the importance or any other behavior here. Um, once you run this application on the device, so you need to check your code before you publish your application. So you need to define important slave over first and that will be final basically. And the here, we're going toe. Call this the create certification channel on this our own when our activity starts. So you don't need to worry because ah, you must create the notification channel before posting any notifications on enjoyed eight point away higher and you should execute This method assumes your application start because it's safe to call this repeatedly because great in an existing notification channel performs no operation. So the next thing we went with intent here and of course, after that, depending intent. So what we wanna do we We went toe here a function for our notification. When we tap on notification, we want to open a our second activity. So we have created our intent and now it's great A pending intent so independent intent we just passed. The context is the first parameter is the second payment to repressed. Just zero is 1/3 parameter. We pass intent and the is the flags. We just type zero as well. So next in this notification channel competent notification Ah, competent builder. We want toe set, the continent tent and we're going to pass are pending content. And after that we're going to set auto cancel. True eso Basically, auto cancel means where we tap on our notification. The notification will disappear. So let's click That is going to see we have the same notification here. And when we tap the notification, we will get redirected to our second activity. So everything works perfectly fine and basically we have created ah, simple and basic notification. In some of the next videos, we're going to create different styles off notification you're going to see and hear inside our system settings. In the notification, we can choose our application. For example, this is our notification name and this is our channel name. So when we tap on that channel, we can see the channel name channel description and also we can disable all notifications for this channel. So it is very important for you to know that creating multiple channels for your application is, ah, quite useful. So, for example, you can create identification channel for your new certifications and the other ratification channel for something like a discount notifications and the 3rd 1 for example for some messaging notification and so on. Eso you don't want to have just one notification channel. That's a bad practice, and having multiple notification channels is is quite useful, so that would be all for this video. 6. Create Expandable Notification: Ah. Hello there. And welcome back. So we're in the previous video. We have created a simple and basic notification. So let's check it out. Okay, clear by. And as you can see, we have here our title, our text. And when we click on our notification, our second activity opens up. All right. So now I have already added this PNG image here inside our Androids studio, and I wanna show you how you can set the different styles on your notifications. So we're going to use ah to expand our notification for their more. So I'm going to convert this image in tow bit map. So he was bitten that factory to decode this resource. All right. And the next inside thes notification comfort. I'm going to set large icon, and I went to use a bit map in the perimeter, so let's check it out. How will that work? So type of this example Number click buy. And as you can see here on the right side, whichever our large icon here, So it looks fine. And now we went to explore this further more So the next thing we're going to set style women to this method the name set style, and we're going toe pass. Ah, notification. Comp it here. Okay. And we're going to use that this big picture style, and then we're going to It was a method big picture, and we're going to pass a bit map. Next. We're going to use another method. Ah, big, a large icon. And we're going to set death to now. So this big large I quit is basically our allow Chaiken. So you will see why we said this to know. So first, let's type here, click this bottom. And as you can see, we have our big picture here. And as you can see, we have this little arrow. So that means we could expand and collapse identification. And when we collapse that these big image disappears and we can only see on that little image on the right side, which is actually allowed Chaiken. So here we're setting the large Aiken, and in this style, we're going to change that. So the eso were patrician. Dead behavior. So where we're setting this big picture, this ah picture from the left from the right side is basically disappearing. So that's because we have said this big, large icon method toe? No. And as you can see, we can see only one image at the time. All right, so that function looks very nice. And the next thing let's Explorer different styles. So instead, this big picture style we're going to is Ah, big text style. So Ah, let's add that and women plea was its method the big text. So here I am goingto pass. Ah, little longer text here. So it will be just random Lauren ipsum text. Okay, lets a runner application to see how will that look? Okay, cleared by. And as you can see, we have our expanded notification here with the wilder text. And when we collapse that these texts will disappear. All right, so next let's delete this big text style method and instead, off this style we're going to is ah, a book style. So basically, book style means that we're going to add the ah custom number off lines inside our medication. So here I'm going. There was a method in book style, and I would do is a method add line. So here I'm going to write just a line one, and then we do this headline method four times. So now it's type line to line three. And let's add one more line at the line for okay, So let's run an application to see How will that look? Okay, just type. And I'm Berkeley by. And as you can see, we have, ah, correct. Four lines off text. So now you saw how you can customize your certification toe, expand itself. And basically, you can expand and collapse your notification based on your content and the the next video we're going to explore our notifications style are furthermore, and I'm going to show you how you can add the extra button inside your notification. 7. Add Notification Action Button: Ah, hello there. And welcome back. So in the previous video, we have learned how to create an expendable notification. So Well, let's check it out. Okay, So what we click buy, we will get this. Ah, expendable notification. All right. So when we click collapse, we're going to see only the text here. Just one line of code. So I'm going to remove this style so we don't need that now. And in this video, I want to show you how we can add an extra button inside our notification. So first we're going toe, add the new method here at action, and we we need toe pass, three different parameters. So the first parameter is ah, image. So this is only used if you are using all the diversions off android. Okay. In the second parameter is the name off the next room button in 1/3 1 is ah, pending intent. So we want to use the same pending intent to never get to our second activity. And we're going to is ascetic or method to set the color for our action button and our small icon. So let's check it out. Okay. Just enter the random number here plagued by. And as you can see, our notification small icon and our actual button changes the color. All right, so when we click this get the bonus extra button, it will lead us to our second activity. Okay, so that works perfectly fine. And I want to show you how we can add some a logic inside our second authority so we can pass some data through our extra button. So here I went to his intent and its method put extra so I can pass some data. So the key will be cookie, and the value will be very basically the number off cookies. Okay. So, ah, now that we have passed that we will go to our second activity and we're going to get intent, get string extent, and we're going toe store. The result off this in 10 data inside our string. All right. And women toe display this ah, number of cookies inside a toast message. So let's check it out. How will that work? And of course, remember to set the flag toe flag update current. So basically what it means, what it does, it will update the value every time you open up a second activity, so it's very important. So now when we click, get bones were going to get navigated to our second activity. And of course, we're going to get the number off cookies. So it's the correct number. All right, So the next thing what I want to do, I would wear the same logic here. For example, we want our user. When our user buys, for example, more than 50 cookies. We want to give our user a bigger bonus. And if he was there, buys cookies more than less than 50. We want to give our user a small bonus. So here, for example, were to say, if cook is less than 50 we're going to display a toast message. You get small bonus and in as brokerage and to set you get huge bonus. All right, so let's open our application and see how will that work? Okay, so this logic is basically ah, simple. I know that you understand this. So let's run the application. And, uh, let's type here some lower number first time. So let's use, for example, 20. Okay, and let's lead by so click extra. But now and as you can see we have toast message, you'll get small bonus. And now let's get back. And let's type, for example. I know 100 Get a bonus and we get the huge bonus. So that will be all for this video. You learned how toe add an extra button inside your notification and how to pass the data. So we're now we're going to add just one more button so you can see how ah, well, that looks so this time the name off our second button will be option. Told us you just an example. So I'm passing the same upended content, so if I click this option to, it will redirect us to second activity. But you can pass a different intent which will lead the user toe some another activity. 8. Create Custom Notification: custom notification allows us to provide custom layout for the contact area normally occupied by the title and the text content while still using the system decorations for the notification icon, timestamp subtext and the extra buttons. Also, there is a way to fully customize our notification, but it is not recommended to ensure your identification looks its best across the different versions off Android. You should always use the standard notification template toe. Build your notification, and you need to be very careful when creating a fully custom notification because you might ruin user experience. So you do need to keep that in mind When you use a custom notification layout, you need to ensure that your custom layout works with different devices, orientations and the resolutions. A. While this advice applies to all of you y layouts. It is especially important for notifications because the space in the notification drawer is a very restricted, so the height available for a custom modification layout depends on a notification view. Usually collapsed view are layouts are limited toe Ah, for the 60 p and the expanded view, layouts are limited to ah, 256 dp. Okay, so now we're going to open our application. So and we're going to create ah customer notification way out. So ah, here in the previous video, we should have ah customized our notification a little bit. So let's run an application to see how that looked like. So let's type your random number click buy and ah here. As you can see, we have ah title. We have text into extra buttons. OK, eso first there were going to create ah to custom layouts for our notification. So the 1st 1 will be for a collapsed view and the 2nd 1 for expanded view. So let's name this 1st 1 a collapsed layout. Okay, click. OK, and here we are not going to use constraint layout. I'm going to tell you why Ah, a little bit later. So we're going to use a linear way out and the height for this collapsed of you will be 64 DP and irritation should be ah, vertical. So here we're going to have just one text view. So let's add the text toe congratulations and the text color to cholera sent text size should be 20 SP, for example. And of course, let's said gravity here, tow center. And let's set the layout height to measure the parents so our text can be ah, center horizontally and vertically. And of course, the idea should be congratulations, sir. Txt. Okay, so now that we have created this first layout, let's create a new one for expanded the view. So let's name this. Expanded the layout and again Ah, let's see, was linear layout instead That constraints layout. I want to tell you why later. So linear layout, layout height this time should be 256 dp orientation toe horizontal this time. And here we want to hear one image view and one text you. So, for the image you were with the truth, this cookies image from our resource directory and ah ah layout within height should be 100 bp. Okay, so now let's add one more text view here. Okay? And, um so ah, layout the wait, uh, for our image, you should be one. And for our text, you should be three. Okay, So our text you should take her should take more space. So let's change the idea for our image, you and for our text view as well All right. So, uh, text should say something like, you are successfully both tank cookies. So this number off 10 should change dynamically. But I'm going to show you that later. For now, it will be hard. Called it like that. And the let's set the gravity to center and layout height to 100 dp for now and the text style to book. All right, so our expanded layout should be ah should look something like that for now and now in main activity. Ah, here we are going to comment out some of those lines of codes because we don't need them. We're going to is a custom layout, so we don't need this content title text and so on. So here, I'm going to create ah removed views, object. So before we continue with our code, I want to tell you more about this remote views class. So this is class that describes view hierarchy that can be displayed in another process. So in our case, we want to display our custom notification layout inside our notification process. Eso the higher he is inflated from a layout resource file. And this class provides some basic corporations for modifying the content off the inflated higher. So basically what this means is, ah that with this removed views the class we will be able tow dynamically, change some of the text and imagery from our layout resource file. OK, so as you saw earlier, I did not use the constraint layout and removed. View is the class is the reason why so removed views support only couple off layouts. For example, adaptive you flipper frame layout, gree layout, grid view, linear layout least view relatively out stack view and view flipper. So, as you can see, we don't have here a constraint layout. So that's why I didn't use it. And of course, ah, remotely was a support a couple off widgets as well. So this is a full list. Ah, analog clock button chronometer, image view, even button progress bar, text clock and the text view. So also, when you're creating a customer layout, you do need to keep this in mind. Okay, so now we're going to continue by implementing this code. So we're going to create the removed he was object, and here we're going to pass two parameters. So the first parameter is a package name. And the second parameter is our layout to the first will be collapsed layout and we're going to create another remotely was ordered it, but this time for our expanded way out file. So here, past expanded layout. Okay. And the in our notification Compal builder, we're going to add a set custom content view. And here we're going toe pass our collapsed layout, and we're going to add the one more line of code set custom, big content. You. And here we're going to pass our expanded layout. Okay, so let's run an application to check it out. So type the random number here, click buy. And as you can see here, we have our congratulations. And when we expand our notification, we don't see our image. You. So we're going to fix that now? Don't worry. Okay? So you can see Ah, this is our fully customized notifications. So we don't see our small icon notification name and time stamp either. Okay, so let's use this. Ah, removed views object. And they were going to set the imagery resource for our expanded layout. So we're going to pass here. Ah, two parameters. So the first parameter is the I d off our image. You. So the idea is cookies image, and the second perimeter will be our source for our image. So let's say it was a draw. But doctor and the cookies. So this school is our image And let's run a replication again. So type the number click buy. And when we expand that we can see that our image you appear now, So ah, next thing we need toe also change this text view so we don't want this hard coded text. But before that, let's change this lay out a little bit. So we want to have the layout gravity here, so our a notification layout can be centered here. All right, so let's check it out. How will that work? Okay, so now our text, you and image, you are center, okay? And the next thing we want to change our text you as well. So when we type the number, we want to show that number in our notification. Of course. All right. So now we're going to do that by using the same remote views object here. So it was expanded, Lee, I would not set text text, and here we're going to pass our our ivy for our text view. And the second parameter is the text which we want to pass. So here, I'm going to say you're successfully both. So we're going to use a concatenation here and refer to is our stringer number of cookies and the plus cookies. Okay, so now let's around the application again and let's check it out. Okay, so let's type some random number here. So you buy. And as you can see here, a notification we have that exact same number. All right, so it works perfectly fine. And now I want toe Ah, at one more thing Here. Also eso Ah, so let's said ah set style here and we're going to pass identification comp it. Ah, that the correct decorated custom. New style. So what? This means that means that our notification will not be fully customized. And now we will be able to see this. Ah, small. I couldn't application name and the time stand. So this is a preferred way of creating notifications. So I recommend you to use this. Ah, this system decorated custom. You style. Okay. And ah, that's pretty much for this video So you learn how to create a fully customized and the partially customized the certification and the next video I will introduce you to, ah, five cloud messaging. 9. Introducing to Firebase Cloud Messaging: Ah, fire based cloud messaging, formerly known as Google Cloud Messaging is a cross platform cloud solution for messages and the notifications for android IOS and the Web applications, which currently can be used at no cost. So a firebase cloud messaging allows the software developers to send the push notifications for their applications. Toe end users through five days consult so push notifications are popular on the mobile devices because they conserve battery life on like pull notifications, which are continually communicating with the developers server for a new information and the can drain devices. The battery life, On the other hand, with push notifications, the Cloud Service X or on behalf of the application and the only connects to the mobile device went there are new notifications with fibers. Cloud messaging developers can send the two types of messages. So the 1st 1 notification messages and the second data messages so notification messages are displayed on the user's device by ah five. Its cloud messaging on behalf of the application and the data messages are directly processed by the application, which is a responsible for delivering the message to the user using message targeting fibers. Cloud Messenger is able to deliver messages toe applications in three ways to a single devices toe group of devices or two devices. Subscribe did to a topics. So we're going to discuss those options in the next videos of this course and also developers. He have the option to create messages in the notification composer off Faibish console, which can send the targeted messages to specific segments off users. These messages are fully integrated with Fibers Analytics, which tracks users engagement and the conversion. 10. Connect Android App to Firebase: Hello there, and welcome back. So Ah, in this video, we're going to connect our application to a fire base. So first, let's check out our applications. So in the last in the previous video we have created discussed a modification layout. All right, so, uh, now, ah, women to close this application because we already saw that everything works fine here. Okay. And now go on Google and the type five is consult. So there are two ways of creating five this project. So one is a from a web browser. So you need to log in from your Google account here, toe five days, and you need to click this project and then follow that set up to create your plot product . Or there is another wave creating project through android studio. So click tools, then fire base than the fibers. Assistance will open. Then click on this cloud, Mr. Drink like a set of fire base. And you need to click first this Correcto five this button. So just wait a little bit and the new window will appear. So here you need toe. Enter the title for your project. So if this is your first time using five days. Maybe it will prompt you to log into your ah fibers account here. But once you do that, just click apply and create this product. So after I enjoyed studio creates this project, you will Cities connected the message, so that means everything is fine. Okay, so now let's refresh our fibers console, and we're going to see our new product appear here. As you can see down below, we have our notification test. So let's click on that. Okay. And after we click on that, we're going toe enter our fibers console. And here, just like truth, data sharing, setting. So this is over the first time when you're ah entering your projects here and down below, scroll a bit and ah, find this cloud messaging. So click on that and the click send your first message. So this is the place where we're going to send the message to our enjoy the applications to our users where you're not going to send those messages right now. But next we're going to click this ad. Five basic fibers cloud message to your application, so click that and apply changes. After that. Enjoys, studio will add some dependencies into your greater bill files. So in this module level, uh, readable file, we're going to see this new line. Will, five days messaging and the Android studio will prompt us that the new version, a new version is available. So let's ah, changed toe. Newer version. Click sink now and it's open up this product level a great bill file. So we also see here this school service. So we need toe change this to a newer version as well. All right, and basically, that's it. So in those a few steps, we have successfully connected our android application to our fibers. And in the next video, we're going to start by implementing these five oclock messaging FBI. 11. Send Message to Single Device: Ah, hello there. And welcome back. So in the previous video, we have a connected our android application to fire base. And, ah, this is how our application looks so far. So here, in our main activity, I just want to change a few things. So I'm going to remove this comment here, and I'm going toe remove this remote view so we don't need ah, custom notification layout. For now, I'm going to remove those lines of codes and just a few things more. For example, Action button here. And, uh okay, so So basically, in this video, I'm going to show you how toe send the push notification toe a single device. So it's very interesting. And we're goingto basically create a new service here inside our enjoyed studio project and that we're going to extend the firebase messaging service. So you're going to see how that will work. First, let's create a new package here. Okay? And then this package were going toe create the new service. So our package should be named something like my service, lower case letters. Okay. And now we're going to add the new service here. So, just like this service and you can uncheck this exported. And let's name our service, my fire based messaging service. Okay. And instead, off extending this service class, we're going to extend the firebase messaging service. So of course, we're going to remove this method. And let's ah, extend this far based messaging service and, ah, by pressing control. Oh, we're going toe override the two methods for now. Well, message received and the own new talking. Okay, so, um, here inside our android manifest file, this service tag is automatically added when we created our service. And I'm going to add this intent filter with our action here, which says calm Google Fiber's messaging event. Okay. And now, after you have ah, added this intent filter, we can close our android manifest file for now. All right, And, uh, here, inside our own message received, we're going to use the remote message object environment. It was It's a method that get notifications. So basically, if there is no, uh, if there is ah, modification, then we're going to execute some code. But first, what I want to do now, I want to copy this. Ah, notification company builder from our main activities. So basically when we send the push notification from our firebase console. We want toe automatically trigger a new ah, notification. So I'm going to copy this. And instead of basing this on message received, I want to create the new method. So, Private Boyd show notification. And here I am goingto fast paced all this code. Okay, so I'm going, I'm going toe modify that just a little bit. I'm goingto set this channel idea string, but this time I'm going to set the number two because this is our second notification and then we to remove this man activity eso ah, for set content title in context. I'm going to use inside that dynamically. So well, it's ah past those values from our parameters. So here title and here text. Okay. And I'm going to remove this Ah, set content spending going tent. And maybe I can remove this large icon for now. And the extra button I'm going to remove that as well. And that bait map Okay. And I went to live just a few. Ah, a few lines of code here, so it can be easier for you to understand. And here I'm going to change from 1 to 2 because this is our second notification, and I'm going to call this a method inside our own message received inside our if, Bart. So here I am goingto pass Ah, title and the text. So basically, I'm getting the text in the title from our fire base. Eso this on message received method is called when when we send a message or push notification from our five is console. So here I am going to also add the notification channel. So because ah, if you're using a P 11 26 or higher, you need to create this certification child. And, uh and we took place this ah method here. So, uh, and I can rename this name and description a little bit. And let's call this create notification inside our show notification on top off our method here. All right. So basically, we can hear inside our my firebase messaging service, we are dynamically grabbing the title and the text from our our fibers console when we send the poor certification and we basically are displaying new notification. So you're going to see how will that work and our services basically done. So the next thing what we need to do. Uh, here inside our main activity, you might wondering. So how can we target just a single device when our application is installed on thousands off devices? So in orderto recognize each device, we're going to need a registration token and the here inside our my registration token method, I'm goingto pay this coats or firebase Instance I d. And from this, we're going to get our unique token i d for each and every device. And of course, it will be the best if you could use a summer firebase a real time database, for example, to store those tokens for each shelf the user. But that's not in the scope of this score. So we're not going toe use the database for now. But don't worry, we don't need that for this purpose. So I'm going to call this matter registration, talking in, ah, inside above. And so here. Basically, we're going to display our token on our own great method. So and the toast messages you can see. So this token ideas Ah, little bit longer. But that's not a problem. And also, we have a lot of this token, so we can copy it, so just type here a token, and we can copy this whole token I d. And we're going to use this same idea to send the push notification toe this specific device. So in the firebase console, we're going to enter here, for example, just simple title, for example, my title and the notification text. Some random text here. This is just an example. And you can set this notification image and notification am That's those two fields, our optional I'm going to show you in the later videos how you can add the image. But for now, we are not going to use that. So click this sent text message button and here based this token I d. And click this red button. And now I just like this test button and basically push notification is a scent. So, as you can see, we have automatically received our notification here. As you can see, it works perfectly fine. So our push notification will be received, even if our application easing the background. So that's a good thing. Okay. And now I showed you how you can target a single device from your fibers console and the next video. I'm going to show you how you can target group of devices 12. Send Message to Multiple Devices: Ah, hello there and welcome back. So in the previous video, I showed you how you can target a single device with push notifications from firebase console. So, as you can see, when we type here in education title in the text, we can select this token. I d for a specific device and a Z concede that device will receive a notification push notification. So now this video, I want to show you how you can target the multiple devices or a group of devices. So, um, you're you might wondering, how can we do that? Well, we're going to use a something called the subscribe topic. So here, just below our my registration talking, I'm going to create the new method here named the Subscribe to Discount. So and I'm going to set this integer for cookies in the parameter. So I'm going to say if cookies is ah last then or equals 2 15 And in his book, of course we So in the first, if block we're going toe basically subscribe toe a small discount. So we're went was a firebase messaging object, and we're going to is a such tripe topic, and here we're goingto pass just a string called a small discount, and we're going to add the own completely snow here. So in this on complete that we're going to say if task is successful is false. So basically, here we went to display a simple Toastmasters, saying something like Failed toe subscribe. So small discount and in else block, we're going to display another Toastmasters saying, Ah successfully subscribed to a small discount, for example. And basically, for example, if our user buys less than or equals toe Ah, 50 50 cookies, then ah, user will be automatically subscribed toe. Ah, small discount. And we're going to use that same a small discount topic toe. Send the push notification from our five. It's console. So you're going to see that? And in this as block, we're going to Basically it was a huge discount topic. So in on great method here inside our ah by button on click listener, we're going to do with this subscribe topic toe discount the method, and we're going to pass the number of cookies as a parameter. So basically, when we click buy button, if our user bought less than 50 cookies, he will receive Ah, small discount topic or he will be subscribed to a small discount topic. So we're going to check it out. Real debt work so you don't have to worry about. It's pretty much simple. And basically, with this sub stripe a topic you can ah, target multiple device. So here let's type. For example, number 30 and we don't click buy. We're going to get the toastmaster saying successfully subscribed to a small discount. And of course we want to get its no notification automatically. But that doesn't matter at this moment. So in five years console here in the target step, we're going to true the topic and we're going toe for a message topic. We're going to write a small discount, so this word has to be the same as in our application. So pick next and this Now click next. So you can also choose from the conversion events for your enjoyed the for your ah fibers analytics. And here we're not going to pass anything for now, so we just like, review and publish, So our application now will receive a push notification automatically. So, as you can see, we should never received a successfully our message so we can Ah, I did it. This is a message from our fibers and we can create another one. And this time we can change something good more for our title in the textile here. Instead of this surrender, man text, we can say small discount and the poor notification text we can say or something like, um, you are now qualified to. It was Ah. Ah, small discount. Okay. And as you can see ah, when we target our ah, such tried the topic Small discount and click review publish. Our notification will be updated. As you can see, it works perfectly fine. So what if we use, for example, a huge and notification topic here? So let's type Here are indemnification title, huge discount and then a notification text. We're going to type something like you are now qualified toe use a huge identification and ah, let's set the huge discount is our topic. So here target huge discount. And when we send this push notification our device will not receive. This is a notification this time because our devices on Lee subscribed toe a small discount topic. Okay, so that works perfectly fine and Now you might wondering, What if we want toe unsubscribed from this topic? Help! Can we do that? Well, it's very easy. And now I want to show you that how how that can be done. So basically, we're going to lose a firebase messaging object and we're going through with this time unsubscribe from topic method. And of course, we were going toe pass A small discount or huge discount topic. It doesn't matter. So let's ah, comment out this line of code. So basically, even if you comment out this substrate the topic. Once your application is subscribed, it is subscribed forever. So you don't need toe around this court every time if you don't want, but it's recommended. So now let's use ah, unsubscribed from topic. And here we're going to say a small discount. Okay, so now when we run our application, let's set this to our own create my thing instead. So when we run our application, we're goingto be unsubscribed from this topic automatically. So let's around application, Okay. And now we should be unsubscribed from the small discount. And now let's check it out to see if we are actually answered stride so We're going to say small discount here and you get small. Discount is a text and let's target our topic to small discount and let's send our push notification. And as you can see, we have No, we haven't to receive the support identification because we hear successfully unsubscribed for this topic and basically, that's it. It is very easy to use those topics. I'm sure you're going to get used to it. You just need a little practice and that that will be all for this video. 13. Send Image Payload: Ah, hello there. And welcome back. So in the previous video, I showed you how you can send a push notification to multiple devices from our firebase console. And now I'm going to show you how you can send the image payload from firebase consult toe Android application. So there is a two options here to upload an image from your PC or to copy You are l So we're going to copy this u R l which I found. Ah, this image. So I window pace that here. And you can see the preview off this image in the notification here, and we want to send that message. But before we send a message first we knew we need to do a summer programming here. So inside our my firebase messaging service, we need to create one string variable and the fourth value will be no. And the second bit map object eso the value. Ah, will The forth valley will be know as well. So here on message received method inside this If block, we need to do something. So first Ah, here. We want to create another if block So basically we're going to check if there is an image you are l passed from the fibers console. And, um if there is, we're going to do something. So okay, eso here, we're going to use this image Rural string, variable. And we're going to store our image. Warrell, in this string Variable. Okay, so basically, we're getting the image. You're out from our fibers console and the here we went toe store a bit map inside our business public, so Ah, this got bit map from your l Um, this is actually a method, and we're going to create that method now, So just stay like this, okay? And I think we should place this method The down bellow, bellow our show a notification methods. So let's place that here. So just, uh, based here. Okay. And basically here we want to convert this image. You are l toe a bit map. So first we're going toe was the u r l object and let's Ah, it was new Euro. And let's based our image. You're all here is a parameter. Next we're going to is the http U R l connection. So here we're going toe cast. Ah, so you know where to be your neural connection. Our you are l from above. So open connection is ah, is the recommended tea was here and now use connection object and its method The set do input. True. So basically, this will fetch a request or so Sorry response. And now connect the method. And next we're going toe create the input stream object, and we're going to store. Ah, our response to this impulse stream. And of course, we're going to return our industry my toe a bit Map. Okay. So ah, there is a try and catch a block needed here in our inside that this bit map from your ella method. So this try, uh, should be on the top like this. And let's ah, arranged this just a little bit, okay? And in Karabakh, we need to return. No. Okay. So Ah, our get big map from your own method is a complete. So basically, this method will convert the image Jor El toe bit map. And now we can ah, safely set the large icon on and we can pass this image bit map. Okay. And now everything should the work. Fine. So we can try that out from our fibers console. So send a text message, select our device click test and the identification has arrived. OK? And it works perfectly fine with no so with no errors. So it is important to convert this. You are a little bit map. Otherwise you will not be ableto set this large icon because settler jackal method accepts only a bit. Map, Object! Okay, so here, as you can see when we leave out this image no ever will present. So that's Ah, that's very nice. As you can see, our default value for this image bit map and image Jorelys No. So, basically, if there is no image Jor El, those values will stay. No. Okay, so, uh, that's fine. And also, we can set here different styles. For example, it's set this to big picture style and also we can use Ah, big picture to set this ah bit map with which we will get from our fire raise. Okay, so let's set the big picture and let's best this. Ah ah bit map Object. Okay, image a bit. Map and weaken Set, of course. Ah, big large I canto now. So when we see our big picture, our lives allowed, cycle will disappear and rivers So you'll see. Now let's start the application again. It's open our five console. Let's space this your l again sent text message selector device, click test. And there you go. So when we collapse so notification we will see our large icon and this big picture will disappear. Okay, so it works perfectly fine. Of course, you can use a real ah, smaller icon. But that's on you. This address, for example, purpose. And that that will be all for this video. In the next video, I'm going to show you how toe pass data payload from a firebase consult toe android application. 14. Send Data Payload: Ah, hello there and welcome back. So in the previous video, I showed you how you can send the image payload from fibres console to your android applications. So let's trick that once more. So as you can see, we have successfully received the our notification and this image from this u R l So that works perfectly fine. And now I'm going to show you how you can send a data payload to your application. So, basically, data payload is a consist off key and value pairs. So here, from a main activity First, let's remove this unsubscribe topic line of court and let's comment out this subscribe to discount so our application can actually subscribe to topic. So let's run our application again and we're going to subscribe to this Ah, small discount once again. So let's type some number below 50. Okay, we get this success message, that's fine. And now I want to show you how you can send and receive the data. Payload from fire is so here. As you can see, we're going to change a here. Just the title for our notifications off. What's bringing this to a small discount? Okay. And go next to a second step target. Here, select a small discount topic. Go. So the fifth step, we're going T o s. Keep those two steps and hear additional options. All fields are optional, so we can adhere a notification child. But we are not going to do that because it's not important. And here for the custom data, we're going to set the key and value pair so you can set as many key and very pairs. Ah, as you want. But for now, it's used. Just one came a repair here. Also, weaken the disabled a sound. And as you can see, our notification will expire in the four weeks maximum period. All right, so, uh, So before we publish our notification, let's get to our my firebase messaging service. And here, inside, all message received the method. We're going to create the one more if block. So here. We're going to check if there is a data. So get data is empty toe false. So basically, that means if there is a data from our five days to receive, then we're going to store the data inside a map object. And of course, we're going to say so strings here. Okay. And now we're just going to look to our look at those values. So here tag will be my data. And let's grab the data by passing this key one. Ah, value. All right, so now let's get back to our fibers console and ah, let's try that out. So, uh, here, we're going toe publish our notification with this key and value pair. Ah, OK. So click publish. And now it's concede we have received notification, but we don't see any data here. Well, because we only log that will locate this values. So let's stretch it out. Let's type here my data, and as you can see, we can see this value one. So that's the data failed. Which we are. Ah, which we passed from our five days console. So it were expertly fine. So, uh, with this data payload, you can best some random data. And then in the application, you you can do some some job hero in all nested received without the user knowing. So that's on you and ah, for the purpose of this course, Let's add the one mawr keying value pairs so you can see that you can receive many data. Pales as you want. So let's copy this once again. And this time let's set Toki two. And here let's create new cure and value Pair key to and value to All right, so let's ah publish now this this certification once more. Okay, publish on the notification is received. Okay? And now in law, get Let's check out. And as you can see, we have very want and value to. So it works perfectly fine. And that will be all for this video. In the next video, I'm going to forgo you can add a sound, vibration and light to your ah notification. 15. Light, Sound and Vibration: Ah, hello there and welcome back. So in the previous video, I showed you how you can pass. Ah, Data payload from a fire based console. And in this video, I'm going to show you how to add. Ah, modifications, sound vibration and how to activate. Ah, notification led on your ah smartphone. So, um, you need to know that Ah, vibration and notification led can be seen on Lee on Ah, really Ah, android device. And not on ah android emulator. So first, let's create a u r I object. And here we're going to store a notification. Ah, sound. So here, let's use this. Get the fourth, you or I, and let's best ringtone manager type certification. So it's really important to it was a type certification. Otherwise, for example, if you was type alarm or something else than ah, different sound will confuse the user. So it's yours. This set sound method and let's bears. This year, I hear All right, so we care successfully set our sound for notification And next let's use this set light the lights method and the first parameter we will be a caller. So it she was a green collar for our edification led. Okay. And the second in the total perimeter, it's use the values for milliseconds. So the first will be 500 milliseconds. And, uh, there are 200 milliseconds. So women, to change the priority for our notification, I'm going to use the priority high on our notification company builder and on our notification channel, we need to change importance level to notification high toe importance high. Well, we're changing importance level because I want to show you how high priority notification look like. Next, we're going to the set vibrator matter toe set the vibration for our notification. Eso here we're going toe pass four different values. So the first value will be zero of the 2nd 250 the last to 250 as well. So let me show you what those values actually means. Eso There are five different values which you can pass here inside the brackets. So the first is delay Second vibrate third sleep forward, vibrate and in the fifth asleep again. So we're not going to use the five numbers just before, So I'm going to set daily to zero vibrato. 250. Sleep toe. 250 vibrate again. Toe 250 milliseconds. So I think this is ah, regular in standard, the vibration for notification. But you can experiment by yourself. That's on you. Okay, so you can set this set vibrate on the notification combat builder. But for the newer devices from a P I level 26 hire, you also need to set the vibrate on a notification channel. So here we're going to their channel object toe set, vibration a swell. So it's use this set vibration pattern. And here we're going to pass in the same values for our vibration. So 0 253 times. Okay, so this one is for delay, So vibrate sleep and vibrate again. All right, so, uh, that's fine. Okay. And remember, you contest the vibration and the modification light only on ah, real device. You will not be able to see that on the notification emulator, but just let me show you. I want to show you how high priority notification look like. So as you can see, we don't get to see ah parody heightened defecation. And that's because Ah, once you set the priority for your notification you cannot change that afterwards. The only way you can change that is toe uninstall your application and install that again. So that's what we're going to do now. So we're going toe to delete or uninstall our application, and we're going toe install our application again so those changes can update so we can see our priority high notifications. And now it's type here, just a random number. Click by and you will see pretty high notification. And this could see our notification popped out here because we have set a priority high, all right? And that looks very nice. And basically that's it for this video. So this was the last video of the scores. I hoped you will learn a lot from the scores, like building a different customized notifications and using firebase cloud messaging successfully. I think for watching this whole course and keep learning and improving your skills and keep practicing. Of course,