Heist the events in this city it's hard.
All I want to actually talk about push notifications.
So let's actually create an android studio project and for the name of the application just a pinhead
app 71 Dasch push notifications
on here.
You can specify the company domain name and the project location and click on next.
And here is a 16 Android 4.1 to the main form and the K.
Click on this and choose any activity next.
And then he had the kind of finish.
So I think it is here are Android project is created.
So now let's actually connect that application to the fireplace.
So at the top click on Tools firebase.
And now here this time click on cloud messaging because we want to actually get push notifications from
the fireplace.
So here just click on cloud messaging and then you can set up firebase clout messaging.
And first of all we need to connect our application to firebase.
So just click on this button.
And here we want to create and you'll find it race project.
So just you can specify the name here and then you can connect to firebase.
So now let's add the firebase cloud messaging to our application.
So just click on the spot in here at f f c m to add app.
So this could be funny.
And then here you just need to accept changes so let's wait a little bit here.
So now the firebase cloud missing message is actually added to our project.
Right.
So now let's create on your class here on the Odama class.
So here inside is Java.
And inside this package just select this package and at the top just click on File Neo and then click
on to upper class.
So for the name of our Java class just typing here my firebase my firebase ID Silvis.
So this is the name of our class and then click on OK.
So this is the name of my class and here is my class.
So let's actually double click on this tab here in order to make this area wider.
And this class my firebase are in the service class is going to extend from the firebase instance IDs
service.
Right.
And here this means that we are going to have actually a fire instance service.
So this class my firebase idea service is going to inherit all the features and behaviors of this firebase
instance I.T. service.
And he actually created this service here in order to create a Torchin for our firebase cloud messaging
so that we can actually just target a single device or a group of devices.
Then we want to actually send notifications to those devices.
So now we need to actually put some lines of code here inside this class.
So I'm going to paste in some lines of code here and then I'm going to explain to you what's going on
here.
So as you can see here these are the lines of code that I've pasted here.
So first of all we actually write it this method on Torchin refresh.
Right.
So the access modifier of this Mfat is probably the return type of Smif it is void.
And let's actually go inside the curly braces of this Meffert And let's see what's going on here.
First of all we have a comment and it says get updated instance Id tawkin right.
So every device that we are going to actually send a push notification device has our instance ID right.
So we can actually get that instance ID and we can actually just share that instance ID with other accounts
that are for example the use there of for example our application is actually using other server side
accounts right.
So we can share that ID for other accounts.
Right.
So it's useful here to get that idea.
It's always useful.
So we created here are valuable of pope.
And the name of this value but is refreshed.
Talken assignment operator and that here I am actually referring to this firebase instance Id Dauth
instance that get talking.
So in this way we can actually get the specific Torchin for a specific device and here line number 21
we are actually printing that value to the console.
So luck that D.
And first of all let's actually just we need to actually provide a track here for are actually class.
So as you can see here it just mistakenly imported this hack.
Here we don't need that.
So I don't want to use this one.
So let's actually deleted delete this one.
And now let's actually go inside this class.
My father was in the service.
Let's create a constant here.
So here I can say for example private static screen task assignment operator.
And inside the code just typing in here for example instance instance ID.
So this is going to be our task.
Right.
And when we don't need this one.
So now I actually put this back here.
So let's actually put a semicolon at the end of our statement and here as you can see this is the value
that you want to output to the lock refreshed tawkin plus refresh tokened.
So this is going to be the token for every device.
And here we are calling the Smurfette send the registration to server and we are passing this refresh
token to dismiss it.
So we are actually using this method as you can see we actually have this method inside this class right.
Private voice sent registration to server and this method accepts an argument of types 3 and and the
name of this argument is actually talking.
So as you can see I didn't put an implementation here for this method because we don't need it.
But let me tell you that this method is used for actually since the end of the talken to serve to other
accounts to other separate accounts.
But we don't need it here but it's always good to have a fresh token for each device.
And now we need to actually just put the service inside the app manifest.
So let's actually just at the top click on View and then click on tool windows and then click on project
and then here DoubleClick.
And this manifests here.
So this is our manifest file.
So now let's actually to go inside the application tab.
This is very important.
We must say the application tab.
So just here and now I'm going to paste in some lines of code here.
So as you can see here I pasted these codes here.
Right.
So we have actually attached and the name of this tag is service.
So we need to add this service to our app manifests here right on our service and here I actually specify
the name of the service and don't call it name the name is not my firebase I.D. service.
So here I am referring to this service that I have inside our package this class my firebase I.D. service
and here we have another intent filter.
So an insight is entered into into filter's patch.
We have this action and right name call name come that Google does firebase that instance Id event.
Right.
So it is really important that we actually put this service here right because of what we want to make
sure that the service is actually loaded.
So we must actually put this service here inside the manifest and inside the application stack.
Right.
So first you need to specify the name which you can actually first to the name of your class and then
you put another intense filter and then you put this line of code here inside this intent filter attack.
Right.
So now let's actually create another class in order to receive the push notifications that you actually
get from the center.
So again just click on this package at the top click on File Neo.
And then here click on double class.
So now let's name this class my firebase my firebase message service.
So now let's actually click on OK.
So here we have this cell with this class.
Right.
So now this class is going to extend from the firebase firebase messaging service.
So let me actually DoubleClick on this tab in order to make this area wider.
So here we have this class my firebase message service that actually extends firebase messaging service
and this means that this class this my firebase Mrs. servies class is actually a firebase messaging
service so now we can actually talk about using it so we can get the push notifications we can't get
the messages from the server and put it here.
So you are all familiar with creating local notifications in Android so you can actually put those logic's
here and you can actually get the messages from the server and create local and create notifications
by using those codes.
So now let me just get put some logic here and then it will make sense.
So as you can see here these are the lines of code that I pasted here.
A line number 14 as you can see we have actually a variable or a constant.
Right and the name of this variable is patch.
So you are already familiar with this tag here private static final streamed package and the assigned
disvalue C M firebase cloud messaging.
And here because we are actually extending this class firebase messaging service here we need to actually
overwrite the Smurfette and message received.
So by using this method we can actually get the message from the server.
So whenever that we actually send a push notification from the firebase by using this method they can
actually get the message and we can actually output this message to the screen or we can output it to
the log.
So as you can see we have some comments here.
So it says to handle if the messages here if the application is in the foreground handle both data and
notification messages here.
Also if you intend on generating your own notifications as a result of received if the message here
is the word that should be initiated.
So you are already familiar with creating notifications and generating notifications so you can actually
put those logic here or you can put those codes here and then here you can just create your own little
notifications here by using the messages that you receive from the server.
So here we have some luck statements.
So the first one is luck.
The.
And we passed the tag here and for the second argument we need to pass the message.
So here is the code from colon plus remote message.
So if we get this remote message from this Mufid remote message that gets from.
So in this way we can actually get the value that from who we get this message right.
A remote message that gets from.
And then here we can actually as you can see we use this code here we want to output this value to the
lock so look that the past tag the tag here for the second argument we passed this value.
And here we put the notification message notification message plus remote message.
Again we are referring to the arguments that we receive from the Smurfette that get notification that
gets buddy right.
So in this way we can actually get the text of the push notification of the notification that you create
and you send two other devices.
So let's see how we can use that here.
First of all again we need to go to Android manifests here and now again in say the application package
we need to actually add this service here.
Right.
So inside this application let me just pasting some lines of code here and then I'm going to explain
to you what's going on here.
So now as you can see here I have this error here inside this file inside the manifest file.
And here is where I actually hovered over this area.
Here inside is a red square here.
It's going to actually show me the error message.
So now let me show you that here.
And it says XML declaration should precede all documents document content and the error is because of
this space here.
Right.
So we need to put this code this line of code here.
Right.
So now let me actually just put it here.
And now the error is gone.
Right.
So if you ever encountered this kind of error you can solve it in this way.
So again this actually goes into this application pack.
So as you can see I pasted these codes here.
So again if you have this service and the name of the service is that my firebase message service.
So here I am refilling to disclose my firebase misses service.
So this is the name our service and here inside is service pack.
We have this intense filter tag.
So inside this intense filter type we have this court action and troit name come that Google that firebase
that messaging underline event.
So this is very important to actually put this service here in order to make sure that this service
does Firebrace messaging service is actually loaded.
This is really important.
So Vinita put up these services these two services inside our manifest file and inside the application
package.
So now our application is ready to actually get the push notification messages.
So analysis I actually have done our project and here is one of these devices and then click on OK.
So now let me show you the web browser here.
So this is my web browser right.
And now it is actually the go to console.
So at the top just click on go to a console.
And here are let's actually select our firebase projects that we actually connected our application
to.
So this is the project that we connected our application to app 71 push notifications and in here insight
is left sidebar here we have these notifications.
Right.
Just click on it and here it says manager notification campaigns and sent messages to engage the right
users at the right moment.
And here we have this button sent your first message.
So now we need to actually provide the message body message text.
Right.
So here I can say hello.
This is my first notification.
Right.
And here you can actually provide a nickname for your message.
So it is optional.
And here it says delivery date send.
Now scintillator right.
So you can actually choose send later and actually specify a date in order to send that notification.
But if you want to choose send now.
And now we need to specify the target.
So the target is going to be our application.
Right.
So here just click on the Select app and here choose this package.
And now as you can see we actually selected this package here for this app and here I can just click
on this sent message.
We have also some other options for example conversation events or you can actually have advanced options
here.
Titel custom date our priorities sound expired weeks.
So here you can just click on send message to actually send our first push notification sent message.
And here it's can actually open this dialogue and it has a video message so delivery date.
Now explicit X Pyrate time for weeks targeting news segment and you can you can see this package.
So this is my prepackage right.
And here it is typically consent so now as you can see it actually guided us to this page.
Right.
And here it says the message is Hello this is my first notification this status is in progress.
Delivery delivery date and the platform is Android.
So now let's actually go to our Android studio and here at the bar then just click on this android monitor.
So now inside the search bar just search for if see him.
So this is the tag.
Right.
If S.M. is attached and if you go to these are my firebase message service.
We put you actually to use this Tadg.
Right.
So now let's actually wait a little bit here.
So now as you can see here this is my android studio and at the bottom just click on Android monitor.
And here inside the search bar just put f c m right.
So inside your my firebase message so is the java file.
We have the stack right.
So if you put this value inside your search bar you can see this value here first you can see the value
it says from.
So this is the value that we get from this line of code here.
REMAUT message does get from right.
And here this is actually a notification message body.
So here it is hello.
This is my first notification.
Right.
So we successfully sent a notification to our Android application.
Right.
So now let me show you another important point.
Let me show you the web browser first.
So as you can see here I actually sent some notifications to my Android device for testing purposes
but now let me show you the emulator.
And now our application is actually running on this emulator right absent 1 push notifications.
So now let me actually create another message here.
So here just click on new message and let me show you the emulator.
And now at the bottom just click on this little circle here.
In order to actually lead an application to go in the background.
OK.
So now our application is actually in the background.
Right.
And now I want to create a new message and I want to send this message to my device to my Android application.
So here I can say this is another message.
Right.
And now for the debilitates to send now.
And the target is user segment.
And here for the select app choose your package and then click on Send Message.
So here just click on send.
Now let me show you the emulator and now as you can see here if I show you the notifications here as
you can see we have this notification here.
It says At 71 push notifications.
This is another message.
So if your app is actually in the background or maybe you are not using your application here at the
moment and when you send a message to your Android app.
Two other devices here the notification is going to appear here.
Right.
This is an other message push notification.
So this was the point that I wanted to show you.
And I think that's enough for this tutorial so if you have any questions please post the discussion
in the course and then I'll do my best to answer all of your questions.
Thank you very much for watching and I'll see you in the next year to all the old.