‫Hello, my friends, and welcome again.
‫So let's continue with the main activity.
‫And we have two things to make in this video, the subscribe button and the reset button.
‫So let me check at first and in order to to create the channel to show the notification, so we need
‫a channel ID and the channel name in order to get the and subscribe to this channel and then read the
‫notifications from this channel.
‫So if build.
‫Dot version SDK dot SDK integer greater than or equal the build dot virgin codes Virgin Codes dot o
‫and the creating the channel to show notifications.
‫The string channel ID equal to get string are the string dot default notification channel ID.
‫Now I will create a channel name equal get string.
‫Here are the string.
‫Also I need a string resource called the default notification channel name.
‫Let me create this string resource and I will give it a resource value weather.
‫So think about a channel on YouTube called weather and you need to get notification on every video uploaded
‫or published to this weather channel.
‫The name is here.
‫From the string, you can see it values strings.
‫You can check it.
‫This is whether you can name it whatever you want a music, sports or what games, whatever you want.
‫I'm going to show you an example of these channels.
‫Now I'm going to get a notification manager instance.
‫Notification Manager equal to get system service.
‫Notification Manager, Application Manager dot class
‫notification manager dot create notification channel, new notification channel and I will set the channel
‫ID here that channel name then notification manager dot importance low.
‫Now I will put p p b1.
‫This is a subscribe button.
‫It will find a view by id r that ID button and read a button to equal find view by id r dot id dot button
‫two.
‫Now we need to start handle that data extras.
‫So if get intent, don't get extras does not equal to null.
‫Then we need to make a four loop set.
‫Agree.
‫Getting all the strings from the set so pay attention with me.
‫This is a for loop.
‫Let me put get the intent get extras.
‫The key set.
‫Look, guys, key set.
‫Key said.
‫I am making a four loop here.
‫I am checking if it is a containing date and no, no, not objects inside the internet.
‫I am putting.
‫And getting all the elements inside the set, cold case set, getting from the get and then get extras
‫that get set.
‫Key set.
‫Keys.
‫All the keys.
‫I'm getting all the keys.
‫Creating an object for every key inside this set called key.
‫And now we are going to execute some codes on this key.
‫So I am getting all the keys inside this intent in order to start getting the data from them.
‫So I create an object instance called value.
‫So give me a key to give you a key.
‫A value.
‫Give me a key to give you a value.
‫So get the intent to get extras and get key.
‫Give me the key.
‫I will give you the value.
‫This is how the SATs work, though.
‫Thank.
‫The key would be.
‫To.
‫Fee and plus value.
‫Value.
‫Plus enter.
‫And part of the package.
‫This is how we import or check and handle the data extras.
‫Now.
‫The Subscribe button.
‫So let me check the subscribe button, which is b one.
‫So B one here, b one.
‫Dot set on click listener new view on click listener
‫on click.
‫What we are going to make.
‫We are going to make a firebase messaging.
‫Not get instance do don't subscribe to topic.
‫What is the name of the topic?
‫It's called weather.
‫So you remember the weather.
‫I told you that it's it's like a channel on YouTube.
‫You subscribe to it.
‫Whenever the admin of the Weather Channel upload a video, you will be get get you will get a notification
‫telling you that hey, the user and the admin of the Weather Channel have uploaded a video add on complete
‫listener, new and complete listener and complete message here string message equal to get string and
‫putting here subscribed.
‫If that the task is not successful,
‫what we will do, we will make the message equal to get string.
‫Ah, that.
‫Or I can put here the message directly without getting the string.
‫Message equal to failed.
‫Just log the tag
‫and message and the toast message.
‫Create a new toast message.
‫Text message.
‫This is how we subscribe to the topic I will make as long.
‫And it's.
‫Fine.
‫Now.
‫Button two dot set on click listener new view.
‫On Click Listener.
‫On Click Firebase Messaging dot get instance dot get token dot add on complete listener.
‫You own complete listener and complete.
‫If the task is not successful.
‫You can use that in successful or.
‫Or cancel.
‫Look dot w.
‫You can make a v tag
‫failed to register.
‫Okay.
‫Desk don't get exception.
‫And here we will return.
‫Then getting a new Firebase Cloud messaging registration token string token equals task dot get resolved.
‫And log and toast string message equal to get string.
‫From the message firebase message token and set the token.
‫So I will create a variable here inside the string resource fold file r dot string dot.
‫Message underscore token underscore f.
‫Firebase messaging token and token
‫though can I'll plus enter create the string and here is the value of this string AFC M registration.
‫So Kenn and I will put here
‫let me increase it
‫token and percentage s.
‫Because it's the variable that we are going to specify, which is a token.
‫Click.
‫Okay.
‫And here we go.
‫This is the.
‫Now we are going to show a toast message and the log the log dot v.
‫Tag message
‫and then toast.
‫Create a new toast message displaying that message.
‫And here we go to now.
‫We have finished this application.
‫Let's clean the project and run it in the next.