Hello this is Martez or Corti.
And in this story all we are going to learn about notification channels in Android 8 Odeo.
So first let me tell you that if your app targets the Android or your Android 8 you must use notification
channels in order to actually create notifications for your applications.
But if you're actually targeting it then versions of Android API less than Android 8 or audio you don't
have to use Actually you're not allowed to use the notification channel because the notification channel
is only used for Android 8.
So if you want to create your own Android application when you want to implement the notification channel
it's better to differentiate between these API.
So for example you can create an if statement and say that if the app targets the versions that are
actually listed and relayed then you can create another notification and other type of notification
that I teach in the course.
And if your app targets Android 8 you can create notification channel.
So if you want to learn how to differentiate between API is an android you can watch the custom view
application.
I think this app is actually in the request that section of the course and the last section of the calls
you can find it there and learn how to differentiate between API is in Android.
So are in another application of the course I teach how to use and other type of notification that you
can actually target versions less than and AP Android 8 and learn how to implement that notification.
So with that said now let's actually continue.
First of all let me tell you that you need to actually update your Android SDK packages so you just
need to Android open the Android studio click and configure and here it says STK manager.
Just click on it.
So here we have the manager at the bottom it says show package details.
If I actually select this option we can see the show package details.
So make sure that you actually update the Android SDK pay packages.
For example we have this one Android TV so we don't want to use Android TV in our discourse but as you
can see we have all of these other packages installed on my computer.
And if it really is the key tools here you can see that we have this Android is the key built tool.
So if we if we can show package details here at the bottom now we can see if it actually scroll down.
Here we have all of these as detailed.
These packages installed Android up twenty six point zero point forty point two actually so this is
actually the card and it is the build tools if you want to target Android 8 and here we have GPO debugging
tools so I don't have this one installed on my computer.
We have Android emulator.
Android is the key platform tools.
Make sure to install these packages.
Android SDK tools Android support love library.
We have deep debugging tools.
We have this one Google Play a fixed extension of a licensing library.
Google Play services and we have this Google word driver and here you can see this.
And Intel X 86 emulator accelerator the hag's.
And so if you or your computer has an Intel CPQ you can actually install this package and we have this
one support repository so forth is actually for this package support repository you can install the
constraint play out for android.
We have a solver for constraints lay out because the constraints they are actually the new you need
to actually install these packages because we are going to actually also use the constraints they have
in this application.
So if we have this android support repository it is very important and Google repository and nautically
can apply if you want to install the packages.
OK.
So I went to the can can.
So let's click on Start in your Android studio project the application name is going to be notification
channel and notification channel.
So I just say See and here we have the company domain the product location.
So just to recap next here are let's here because we want to actually only target and rate AP Android
8 and we do not want to differentiate between versions of and with the Android operating system we just
use Android eight point zero as the minimum SDK and we just click on next choose MT activity next and
for the activity name just don't change anything here.
Just click on finish.
So let's wait a little bit here.
So now that a project is created Let's close this dialogue here.
Now on the left hand side we have this and view let's open this folder app and let's open this race
folder.
Let's lay out for that and double click and this activity underline made that example you're going to
design the user interface here first.
So we have this hello overload takes you at the center just selected and then press on delete key on
your keyboard.
Now you're going to actually say that we have an 80 text inside or kind of straitly.
So inside this palette section discrete context.
And in order to find it it takes the first one is takes you and the others here.
For example we have a plain text password text password.
These are 80 texts or in other words text fields that we can enter a value.
OK but this takes view is not a text field it's just a taste really it's just a label.
If you are on are you a symbol of her.
So for these other components for example you can see if you have the time we have that date for example
you can enter the time that if you can enter the date date you can enter the number only number.
All we have this one a number assigned.
Only the signed numbers so what's what is the sign number the signed number is actually the positive
and negative numbers.
And we have the unsigned number that actually only accepts the positive numbers.
So in this case you're going to learn more about these kinds of differentiations in Android If we have
the number decimal only this.
Does it it takes only accepts the simple numbers autocomplete X and Monte autocomplete XP which I actually
teach more about this one.
These ones are later in this course.
But for now we're going to use the plain text.
So just select it and drag it here into this constraint.
And here you can see that we have this component through Section discount punch through section has
a constraint laid out inside this constraint lay out.
We have this edit text right.
So now I put this edit text here and I can see that some constraints at the left hand side and the right
hand side.
I actually created the reason that it has created these constraints for me is that this option here
is iconic and see that it says auto connect feature of the constraint.
This feature is now on turned on and you can see that these constraints are created automatically for
me if you don't want these constraints created for you which you just need to turn off this feature.
So here you can see that we have the left constraint and the right right.
So let's create a constraint to the top to the bottom edge of this tool bar OK.
And now let's select this text and let's say that we have the ID is going to be EDT EDT.
What's movie watch movie and the person on your keyboard.
And for the text you can't just delete the text or actually did it to the text value of these text attributes.
We have this hint attribute and here you can see enter and name of movie.
So here we can see that I actually enter this hardcoded value it is not recommended to use hardcoded
values you can create a strange resource here inside this radius folder inside a string that exemplified.
And then you just need to refer to the name of that string resource.
But here are because we use it in later discourse you're going to learn about this feature or in the
previous application you have learned how to use string strings that I am a find.
We're not going to use it.
But if you want to you can do that.
And it is recommended to use the strings resources so let's person precedented Janet Hubert.
So here is the text.
Let's also just put dot dot dot.
So now is more meaningful.
Now we are going to actually say let's look at a bottom here.
Inside are constantly out.
So inside this pulse section just click on all and then the spot to strike it here below.
This takes you and here you can see that the left constraint and the right hand strike is created.
Let's create a constraint to the bottom edge of this editrix so you can see this little circle.
This green color this green circle that is actually pulsating.
Let's create a connection to the bottom edge of this.
It takes here.
Now the connection is created you can see that this little circle here is now red that is pulsating.
So now let's select this spot in 40 already we can say between BT and votes movie and then present and
future on your keyboard and for the ticks you can say post notification post notification
for movie
and then precedented here on your keyboard.
Post notification for movie.
And here let's add another button.
So just write this posting here.
Do this part and your That's created a connection to the body image of this.
But in here it is post notification for a movie and then select a spot in for the OED.
They've in here between settings billions movie movie settings and then precedented on your keyboard.
And for the text to typing here sittings for movie notification for movie notification
and then person enter key on your keyboard.
So now that we have these buttons and this text here we can go ahead and enter the codes that are required
in order to create a notification or notification Channel for Android 8.
So now let's see how we can do that.
So first of all we need to open the Android view here at the left hand side and we have this job folder
open it and we have this first package right.
Right click on this package here new and then click on Java class.
So for the name of the class we are going to say notification notification handler.
So we're are going to create a handler for the notification that the notification channel that you are
going to create and here you can see that it has a visibility Popbitch modifiers non-thought just don't
add anything here.
Make sure the package is this is the value that you actually specified for the package of your application.
So if you're just right click and this package is going to automatically put this package here.
In other words you don't have to change anything.
Just name the class district technology.
So here it is our class that's DoubleClick and establish order to make this area wider.
Now this class must extend from the context context of wrapper class.
So let's see what is this context wrapper in Android documentation.
So here it is our documentation you can search in Google context wrapper or you can just enter this
you are a developer and right dot com slash defense slash Android slash content slash context wrapper
that ASTM it.
So here you can see that this class directly extends from the context class.
So the context wrapper class is actually the context.
Right.
And here it says proxying implementation of context that simply delegates all of its calls to another
context can be subclassed to modify behavior without changing the original context.
So first let's see what is context.
So I just opened another tap here for you and I searched for what is context in Android.
We have this line here in stack overflow.
So I just click on this link here.
What is context that Android.
And I'm going to just scroll down here so here it is the accepted answer.
It says putting it simply as this name suggests it's the context of current state of the application
or object.
It lists newly created objects understand what has been going on.
Typically you Corlett to get information regarding another part of your program.
This is really important.
You just cut the context to get information regarding another part of our program.
It is you can get the context but if by invoking the application context context Meffert get base context
Meffert or it's then in a class that extends from the context such as the application activity service
and intense service class we use context to access the features outside of our activity.
So in this case you want to use the notification channel.
That's why we use context here.
You want to access some other features that are actually outside of our activity.
So if you're going to use the context wrapper class which is a subclass of the context class.
So let's open our Android studio here to consider our class notification handler class extends from
the context wrapper but it's sooner or later and it says there is no default constructor available in
Android that content that context wrapper so we need to create a constructor inside this class.
So first we need to say that it is public the name of the constructor must be as the name as the name
of the class.
So notification handler and I just put a pair of practice's here.
This constructor is going to accept an argument of type context.
So we're going to create a create a parameter here.
So what's the difference between plie here and argument.
The argument is the actual value that we passed to some effort by the parameter is when you actually
declare a prime it'll for you for your method.
OK.
So whenever For example later when we actually call this constructor we want to pass an argument of
tokens context.
It is called argument but when we want to create it we are going to say if we have a plummet here of
type context for this method it's so that's the difference between an argument and a prime actor in
Android.
So inside is constructor we can say that need to call the super constructor super and to pass the context.
That's it.
So now inside is class if you're going to create some instance variables.
So the first instance variable that we are going to create inside our class is going to be of type notification
manager.
So we're going to say private notification manager notification manager and the name is going to be
a notification manager semicolon.
Now we're going to create another instance variable but this time this instance variable is going to
be public because we want to use this instance variable from another class main activity.
So we're trying to say public static final.
So as you can see this is actually a constant.
This is not a regular variable.
This is a constant.
And when it is created it it cannot be changed.
They do it and it is initialized it cannot be changed later.
So public static final and the name of this variable here is going to be watching movies so whenever
you create a constant in Android.
Make sure to actually make it uppercase instead of a lowercase.
So all of these letters all of the letters of the name of this constant should be uppercase I'm going
to say Vought underline movie Bodyline and notification channel notification other live chat on other
line ID so there is that I actually chose this last name is that I wanted this to be actually meaningful
for you.
So if you're creating your own idea you don't have to actually choose our name like this one.
You can just choose a short short shorter name but I just want to make it more meaningful for you.
So I'm gonna choose this name and as you can see here I didn't specify the data type of this constant
so that is fine and we need to specify the type which is actually strange.
And I put two codes here.
And as the value I'm going to say watch a movie notification noti fixation channel semicolon.
So let's actually say create a new line here.
Now this is the idea about notification and right now when it is specify a name for it for notification
Channel and this name is going to be visible to the user.
OK.
So again it is actually the public static final strange and here I'm going to say what movie notification
name so I'm going to copy this name here.
And I'm going to put it here.
And instead of ID I'm going to say name assignment operator and as the as the value we're going to say
watch movie notification.
So here we said watch movie notification channel ID as the value here we need to pack if you need to
add ID here to the value of this constant here watch moving notification channel ID.
And if you're trying to copy disvalue here and we will be able to paste it here as the value of this
constant And we are instead of the we are going to say nay.
So make sure that these two values are actually different because this is our ID and this is the name.
So we just put a semicolon here.
Now that we have this instance is actually created inside our class we can go ahead and create a method
in order to create the notification channels.
But here instead of actually using these long winded values for example we can actually use only the
first letter of each word.
So for watch moving notification channel Id say W M What movie notification channel ID right or for
this video here again we can see viage movie notification channel name.
So as the last name we just put the whole word here.
So its much more better.
And it can be more Beder if you want to show this value with its name to the user because it is actually
a user visible value.
So let's scroll down here after this structure that we created inside this notification handler class.
Are going to create a method and lets say that this method is actually Puplick because we are going
to use this method from our main activity class.
So we are meant to stay private and return type of this if it is void the name of this method is going
to be create notification notification channel.
And then I just put a pair of this year let's open and close this method by using these curly braces.
So first thing inside is create notification channel Meffert we are going to create an object of type
notification channel.
So we going to see notification channel and the name is going to be notification channel assignment
operator new notification channel object.
So here we are creating a notification Tennent object and we are assigning get to this variable name
as notification channel.
So new ratifications are here we need to pass some arguments first we need to pass the ID.
So I'm going to just type in your ID and it's going to find our constants here so we need to actually
name it as watch movie notification channel.
So the first one here is the ID come to and now you need to pass the name the name here is watch movie
notification channel name.
So the second one is name.
Or we can actually just delete the idea and just with the name here comma that create a new line so
that we can see what's going on here.
So we passed the OED as the first document the second argument is the name and the final argument is
going to be the importance.
So the importance attribute is going to specify the priority of notification.
So I'll talk more about this feature later.
For now we need to refer first we need to refer to our notification manager instance variable.
I notice that we haven't still initialized this variable going to initialize it later.
Just for now just referred to our instance variable notification manager dot and here I'm going to type
in here.
Importance just like in here hit importance with a capital letter is we have importance high importance
low max default mean non unspecified.
For now let's choose default.
I'll talk more about these other values for now just choose importance underline default.
So let me create a new line here.
And finally we need to put a semicolon at the end of our statement.
So now we need to specify the attributes of what modification to.
So I'm going to paste some lines of code here so as you can see these are the lines of code that I pasted
here.
First of all we actually specifying the Enable lights of the notification channel and we pass the value
true to this method.
So let me hold down the comment on my keyboard and then click on this method here.
If you are using a Windows you just need to hold down the control on your keyboard and then click on
this method.
So here it is the main thread and here it is the documentation of this method and if you cannot access
the documentation of this method you can easily just search for this method in Google in order to find
the on line documentation.
So here it says sets whether ratifications posted through this channel should display notification lights
on devices that support this feature.
OK so it is going to specify the notification lights.
Let me actually close this one here and now we have this method so we have this one set light color
color of that red.
So it's actually self-explanatory.
And here we have the set show badge.
True we passed the value of this method.
Let me actually take you to the documentation of this.
It says sets or the ratifications posted to this channel can appear as application icon badges.
In a launcher.
OK so you can actually specify an icon for your notification.
So let's close this file.
So we passed the body of truth to this method.
Here we have this method not an internal data set.
Lock screen visibility notification that visibility public if asked Is this a valid reason.
So let's take a look at this the documentation of this.
If it is sets whether notification is posted to this channel appear on the luckiest screen or not and
if so whether they appear in the data for.
So here this Smurfette sets like a screen visibility is going to specify whether you can show this notification
on the screen or not.
So let's close this file.
And finally we have get notification manager Meffert.
So we haven't still called created the Smurfette.
But here we are just calling the Smurfette in order to get the notification manager.
Remember I told you that we haven't still initialized our notification manager instance variable.
So here are inside this method that we are going to create later.
We are going to initialize our notification manager and we are going to return the initialized notification
manager object from this method.
So it is gets much a manager that create notification channel and we just passed the notification channel.
Object to this method.
So after the end in curly brace of this create notification Tanel Mefford.
Let's create a method here but here I notice that I actually declare to dismiss it as private.
It should be public because the main activity class is going to access this method later.
So public Woit creates a notification channel and hear it before the ending curly brace or what class
I am going to say private.
So now we can actually declare or dismiss it as private void or private.
Our notification manager you need to specify the tenth value for my friend gets notification manager
get a manager or a pair of prentices so that it's open and close this method by using the curly braces
and inside this method we can say that if the notification manager rowdier it but that we created above
is actually no and it is not initialized then we can open and close this if statement by using these
curly braces we can say notification manager assignment operator.
So we need to cast this object to our notification manager object say Get system service context that
notification service semicolons.
So remember I told you that by using the context class we can access the features outside of our activity.
So here it is one example you can access the notification service by using the context select and create
a new line so that he can see what's going on here.
So now in this way we can initialize our notification manager opti after the end in Crilley place of
this if statement.
We can't just say in return notification manager vacation manager.
So now whenever we actually call this method not get notification manager we can get the initialized
up of up notification manager.
OK now here it's time to create the actual notification object that you're going to post to the user's
device.
So if you need to create an error method for that.
So before the ending brace of our notification handler class you are going to say Puplick.
Again this method is public because we are going to use it later from another class.
Public notification dot builder notification that builder This is the type and the name of them if it
is going to be create and return watch movie notification watch movie notification and put pair apparent
Apprentice's here.
And we need to specify some parameters for this method.
So it is going to be of types three and the first one is going to be three title text comma.
Strange.
Body Text.
The name is but it is the name of this parameter.
So let me create a new line here so that you can see what's going on here.
So these are the parameters.
This story in the title text string by the text.
Let's open and close this method by using these curly braces.
We can say return new We're going to create a new object of type notification that build there.
So notification that builder Now we to some arguments the first one is the actually the context so we
can say good application context in order to get the context.
Comma I meant to pass the channel ID.
That is strange.
So we already created our channel ID.
So the name is a watch movie notification channel ID so we can pass that value here.
Watch movie notification channel ID.
So here it is the ID.
So here let me create a new line after this come or we can create a new line and we can see that we
are actually creating a new object type notification that builder.
Here are the arguments that we passed to the constructor get application context watch movie notification
channel ID.
So lets see what we are going to do next.
So here is the object right.
The new and here it is the whole object.
And here we can call a method on this object like calling it an invaluable or a method maybe.
So we can say that sits.
So here it is.
Here in Memphis.
So for example we have set small icon set auto cancels set content text.
We have the title text or we have the sets content title actually.
So here we are.
We call this method and we passed the title text to dismiss it.
And that can create a new line and say that set content sits content to text so if you have the content
title that be called before and B have the content text so the text is going to be body text to be passed
to put the text that is again on the line.
We can also specify an icon for our notification so we can say that set smile icon.
So we haven't actually created an icon for notification but now I am going to show you how you can do
that.
So let's open the Android view.
And if you want to know how to open the Android you just need to at the top you just need to click on
view to Windows and then project or you can use the shortcut.
So for Mac it is a command to one.
So here we have this arrest folder.
So we just need to right click on the rest folder here and we can go to New and then click on image
asset or you can actually create a vector asset.
But here we are going to create an image asset.
And here we have this icon type.
Click on this little triangle here.
So are going to specify the type of the icon that we are going to create.
We have the lantern icons.
We have the action bar and tap icons and we have the notification icons.
So just click on it and here it is.
It is the name.
So for the name just typing here.
Watch underly movie.
And we have that as a type.
We have the image clipart the text so just choose clip art.
And we have the clip so just click on these little Android image these clipart.
So here this window is open for you so that you can choose an icon in say the search area.
Just search for movie or watch or maybe movie.
So here we have for example this one local movie movie two in box so we can actually choose this one
movie right.
Or movie Creation or some other icons.
So just search for a specific icon that is actually related to your notification I just click on OK.
Now it's 3 am.
No.
If you want to you can specify some attributes here.
I just am just going to leave it as default and I'm just going to click on next.
As you can see here it is going to create some variations of the icon we have x x HTP.
So this icon is going to be used for more now actually high quality resolutions devices.
We have a switch the CPI HTP and NDP.
So these are the icons that are going to be created and your app according to the device that your appearance
on is going to actually take automatically the specific icon that is actually suitable for that device
and just click on x.
So here again you can see that it's going to actually specify the location that your icon is going to
be saved inside the tribal folder.
And here just don't change anything just click on the image.
Now inside destroy Bill folder we have our motto watch underline movie the P.A. we have four images
STPI and x and x x x.
So inside the practices of these sets smart I can MFL it because they are taught bell that watch underline
movie.
OK.
So let me double click on the step in order to make this area wider.
And the next attribute that we want to specify is that sets or to cancel.
And we want to pass the truth to the Smurfette.
So here let's click on the set of the handsome effort in order to see the documentation of this if it
says make this if a notification automatically dismissed when the user touches it.
So we just pass the value true to the Smurfette.
Let me close this file.
And if you want to you can specify some other attributes.
So you just need to put that in here.
For example we have some other attributes or methods.
For example we have an action you can add an action to this.
But if vacation add extras add person extend such actions.
We have set badge icon typeset category so lots of for example set color set colorized set content intent.
So in order to see how this fits works you need to actually search for these methods in Google or in
order to find them in for example in stack overflow which is a great Web site if you want to find solutions
for your apps.
Or you can just read the documentation and you don't have to read always read the documentation.
But for example I'm going to show you an example for example set action right.
For example set action for our notification.
So we need to open the Google.
So let me open the web browser.
So here inside the search area we can't say set action.
OK.
Notification not the fixation.
So you just need to put some important keywords inside the search area notification and right.
That's it.
I just to a person on my keyboard.
So here we have a stack overflow post and we here we have the official word and documentation notification
that builder.
So I'm just going to click on it.
So here it is the android documentation and inside its documentation I'm going to search for a method.
So I'm just going to hold down the command on my keyboard and then press on the leader on my keyboard.
And if you are using a Windows machine you just need to hold down the control key on your keyboard and
then present the letter F key on your keyboard.
So I'm going to search for a method set actions.
So take a look at this Meffert.
It has altered the complete list of actions attached to this notification.
So by using the Smurfette we can actually alter the actions but in order to alter the action first you
need to add an action to your notification.
So if I actually scroll to the top here you can see it's public if it's the first one is an action and
this action exits and accepts some arguments.
The icon which is of the integer char sequence which is actually the title it is actually the same to
the string data type.
And we have the pending intent intent this method.
It is actually deprecated in API level 23 and it says use an action action.
So if we have this method of action that accepts notification that action action and an action to this
notification.
So I'm just going to click on this Mefford.
So here it says notification that builder at action it is an action to these notifications actions are
typically displayed by the system as a button Aitcheson to the notification content.
Every action must have an icon.
So notice that it says must have an icon first to be square and matching the holo dark action bar visuals.
So it is actually a hint or for you or me or actually a tip for you so that you can actually specify
the design of your app and it has a textual label and appending intent or notification in its expanded
form can display up to free actions from left to right in order.
The other added actions will not be displayed when the notification is collapsed however so be sure
that any essential functions may be accessed by the user in some other way.
For example in the activity pointed to by content intent.
So here it is the method.
And lets actually click on this pending content and see what is this pending intent.
So you can I should read the documentation of this pending intent and see what is the spending intent.
And by the way in the next story only the next application that we are going to build in this course
we are going to learn more about pending intent and how to add an action to our identifications.
But for this notification channel I'm just going to show you how it is implemented for Android.
So now let's go back to android studio here.
So it's enough for these attributes again if you want to you can specify some other actions or for example
attributes for your ratification but for our application it's you know finally we just put a semicolon
at the end of our statement said although he has said and done so let me add these spaces here.
And the final method that we are going to create inside our notification handler class is called notify
the user.
So after the end in curly brace of our Meffert create and return watch moving notification I am going
to say again Voyt notify notified the user and then pull up her refracts this year we are going to specify
some parameters what this method the first trimester is going to be of type integer so int ID karma
or can say notification ID it's more meaningful notification Id come up notification that builder notification
that builder and here the name is going to be notification builder situation.
BUILDER.
So just open and close the Smurfit by using these curly braces.
Let's create a new line here.
So now inside is Smurfette.
So inside this method we are going to say get notification manager that notify notify.
So first we need to pass the ID.
We have the ID here we say notification Id come on and we need to pass the actual notification optics.
So we have the notification builder here.
So we say notification
dot dot dot.
So there reason we say notification builder here you are referring to the argument that built this build
Meffert is going to return an object of type notification.
So it's very important that we call the Budiman fit and this notification builder and we are going to
see how it is implemented and how we can use this method in order to notify the user.
But for now we need to implement this method like this.
Now I think our class is done notification handler is actually finished now we need to go into that
into the main activity class.
So lets go and say this man I think the class here.
So lets first run the application
and here you can see that the app is running on the simulator.
So we have an edit text here and we have two buttons right.
First let's create an ID takes inside our main activity class.
So lets say that we have private text and the name is going to be EDT.
Watch movie semicolon.
So now we need to go inside and create Meffert and we can say it it imma watch movie assignment operator.
So here we don't cast to and edit text objects anymore.
Before we had to manually just put up refractors and say edit text right.
This is not necessary anymore.
In the newest version of Android studio we can just say find the ID artist Id that EDT to watch movie
semicolon OK.
We also have two buttons post notification for movie and settings for movie notification.
So we don't have to create a variable for a pattern and then initialize are valuable because we just
want to make these buttons just listeners for the users clicks or taps.
So we just say inside this and create method we just say find the way Id are that Id dot between.
So for example we have this a billion watch movie that sets on click listener and we just pass the context
which is this main activity that this.
And we also have this one sentence for movie notification.
So again we say find we will find the ID are taught ID dots between movie settings that set on click
listener main activity that's this.
And finally this main activity class must implement the IView dot on a quick lesson or interface and
inside the class we need to override the on if it.
So now the error is gone.
And inside is actually effect let's create a switch statement.
And let's switch between the values of the ID of the of view argument that is actually clicked inside
the switch statement.
We can we can have case that ID that PTEN watch movie Colan break and we have case on that idea that
PTEN movie settings Colan break.
OK so now we need to create some instance variables inside our main activity class.
So let me create a comment ins and outs of variables Swon is going to be private and the name is going
to be notification handler.
So it is actually offtake notification handler handler and the name is that a vacation handler cynical.
So this is the class that we created ourselves.
When it going inside is uncreate Mefford and initialize this notification handler so assignment operator
new notification handler and we need to pass the context which is going to be main activity that this
OK semicolon.
We also need to create an ID for the not reputation that we want to post to the users device.
Notice that inside this notification handler class let me open it.
We have an ID for that channel.
OK.
But inside the main activity class we want to have an ID for the notification.
So if you are going to have two kinds of IDS the first kind is for that channel which is called Channel
ID.
The second one is notification ID.
So inside its main activity class here I am going to say private static final INT and the name is going
to be watch movie for each other like movie underline notification underline ID.
OK not a challenge Id is the notification ID assignment operator.
So it is like teacher and it must be a unique value.
So just pass the value of 1000 to this constant.
It doesn't really matter what value you assign to this constant but it must be unique.
It has to be a unique value.
Now we need to create a method called Post notification to users device and also inside this main activity
class before the end in place of our main analytical s.a.a to say private voit and the name is going
to be post notification to use your device and then put a pair of practices here so you know you're
going to specify some parameters for this method.
The first one is going to be in and the name is going to be notification I.D. notification ID comma
and the second parameter is going to be off the strange and the name is going to be title text.
So just open and close this method by using these curly braces inside the Smurfette to create a switch.
They can switch and switch notification ID so just open and close the switch statements by using these
curly braces.
And we a case and as you can see inside this class we created an ID name as a watch moving notification
ID.
So we were going to see such moving notification Id call and if the ID of notification is watch moving
notification ID then we can't say so before this.
So it's they meant inside this post notification to use a device we need to create a local variable
as a type a notification that builder.
So they've been here notification that builder and the name is going to be notification there.
And then initially we are going to assign the value gnarl to these local but semicolon.
So we say case watch moving notification Id break.
So let's go inside this case and let's say we just need to refer to our notification law litigation
builder local variable and we're going to initialize it in this way.
We have a variable on an instance variable named as notification handler right inside our main activity
class here and we initialized it inside our uncreate method.
So we're meant to refer to this notification handler instance variable not create and return watch moving
notification so that we create a new line so that we can see what's going on here.
So we need to pass some arguments to disprove it.
Let me call this method again so that you can see what are the arguments that we're going to pass this.
The first one is the title text and the second argument is going to be body text.
So the for the title text we can say hateful text.
So we already are dismembered posts santification to use a device has applied picture of type string
and his name is title text so we just passed the title text to the Smurfette.
Come on.
And we have the body text.
So the politics can be anything we can say for example of watch movie or this is a great movie.
This is a great movie you can put whatever values that you want here.
So just put a semicolon at the end of your statement.
So after these suits they spent here.
We have this ending.
This is the end in curly brace of the sweet statement.
After this any curly brace I am still inside this post notification to use a device Meffert and going
to create to create an if statement so if notification builder is not equal to Knol or an invalid value
this is not right.
If it is not equal to all and this is actually the notification builder has a valid value then we can
notify the user then we can say notification handler I am referring to my instance variable notification
handler that notify the user.
So we need to pass some arguments to this method.
The first one is going to be the notification by D.
So I want to say watch movie notification ID so it is capitalized.
Watch movie notification Id come on.
And finally 10:22 notification bill there.
So we just passed the notification bill that we created inside site is post notification to user device
Mefford.
OK so this is the implementation of our post notification to use the device method.
So here let me show you the emulator.
So for example the use type something inside type something inside is added text.
For example the name of the movie for example Star Wars right.
And here the user clicks or taps on this post notification for movie bottom.
You want something to happen so let's go back to the studio.
And so does Uncle Smurfette in this case a statement or the idea that between the watch movie case we're
going to say post notification to use their device.
We're calling this method.
So first we need to pass the notification ID.
We already created the notification device moving notification Id come on and we need to pass this the
total text.
So we want the title IX to be the text of the text so we just refer to our editrix object.
EDT provides movie that get mixed dots.
This is very important to think Mini-Cooper converted to a string value because they get text Leffert
returns an object of type editable.
So if you want to learn more about this you can actually take a look at the documentation or you can
just click on this get text message hold on the comment on your keyboard and then click on this get
text Meffert.
If youre using a Windows machine you can actually take a look at.
You can hold the control key and then click on this Meffert you know that it actually takes a look at
the implementation of this mephitic and see that the return type of this method is actually editable.
So let me click.
Close this file.
Now let me create a new line here.
So let's run tiap let's run the app and let's see what happens.
Let me show you the emulator so I'm going to enter the name of the movie.
So the name of the movie is for example Star Wars and I'm going to click on this post notification for
the movie.
So as you can see here it doesn't create a notification of for our Android application.
So there is a bug inside our app.
OK.
We need to find the park.
There are two ways to find the park.
You can use the debugging tools or you can actually just simply take a look at your node notification
handler class and say this notification handler class you can see that we have this method in our grey
color.
If I hover over this if it says Meffert create notification channel is never used.
This means that we haven't called this method from anywhere.
We need to call this create artificial channel so that notification channel is created.
Remember I told you that for Android 8 or audio we must create a notification channel.
Otherwise it doesn't.
It's not going to create a notification for the user device.
So we need to call the notification.
Vinita call the Create vacation channel inside a constructor of this notification handler class.
So after calling the super constructor we are going to say create notification turnon that's it.
Now we can run the application.
Let me show you the emulator.
So inside these edits I'm going to just step in here Star Wars.
Now I'm going to click on this post notification for a movie.
As you can see there was a sad.
I think you heard the sound.
And we have the notification here if I show you the notifications you can see that it says Star Wars.
You can see this movie icon.
This is the name of the app and it says this is a great movie.
Right.
So now I want to talk about this one.
These settings for the movie notification if you want to make this one work so that whenever the user
clicks on this button it's going to open up the settings application of the user's device and it's going
to open the settings page for this application for this notification actually.
So each application has a notification settings.
So let me tell you that.
Let me show you the application So for example we have this app in C at right e-filed launch.
Click this app or if I select and hold this up for a moment here as you can see I just alone clicked
this app.
And as you can see it this app actually let all the dialog is opened.
For us it is Star Wars.
This is the great movie notifications if we click on it here if we click on this notifications as you
can see nothing happened.
But it is app info.
If I click on this app info you can see this is our application so you can open your settings application
inside your app inside your device and then click on settings and then click on the apps and then you
can see for example your apps there if we click on a specific application you can see up activity like
this one on Istar for stop.
And here we have app notifications.
If I click on it you can see it is on the notification is on if I actually make this up.
It's going on notifications for this application is going to be off and it's not going to create notifications
for this application.
And here we have the categories right.
Darby You m in C name.
So if I click on it this is the notification channel the category's is the channel.
If I click on this one here you can see the attributes of our channel.
So if we go into this android studio you can see if like when we created the notification turned on
here you can see these attributes that we specify here.
So for example the id the name the importance.
So here you can see that it says the importance is high it make sound.
We have urgent medium low.
So I just use the default so the default is high on it and it does create a sound like select this one
urgent make sound and pop on a screen so that if this one let's go back go back and back.
So let's open our application let's this time just change the name of the movie to for example mask
and let's click on post notification for a movie as you can see the sound and there that a vacation
pops on the screen.
This is a great movie right.
So let's.
So here I created this spot here in order to guide the user directly to the citizens of this specific
notification channel so that the user can actually just easily change the settings.
For example change the importance or whatever that is related to this channel.
But here are there is an exception here.
Here I want to show you that when you code it in notification channels for example here we specified
there.
Watch the importance to be default for this notification.
Right.
But when the app runs and when you create the notification then of which if it actually for example
changed this importance default to importance to low.
So let's change it.
Importance to for example here is not going to affect how our notification of this apple.
So let's run the app because if we changed the settings in say the settings of the notification.
So for example let's give it a name for example against Starforce and ask recomposed not a vacation.
As you can see now this notification pops on the screen.
But here I sit important slow so it doesn't affect how or how our notification works when you change
the settings inside the settings.
Activity of this notification that specific settings is what matters here.
OK.
When you change the code it doesn't affect it because the user has already changed the settings of the
notification inside the settings application.
So here we want to create a way for the user to access the notifications directly by just clicking on
the spot.
Let's scoot into our Android studio and let's go inside the main activity class and let's see how we
can do that.
OK.
So inside is main activity class.
Let's scroll down here.
So before the end in curly brace our main activity class we are going to create a method.
So it is going to be private and that the return type is going to be void in name is going to be open
notification notification settings.
What movie channel.
So let's put up pair of here and let's provide a privater of types 3:47.
So it is going to be a tape strange and the name is going to be watch movie channel.
So let's open and close this method by using these curly braces.
So here first we need to create an intense object so intent and the name is going to be set Henning's
intent assignment operator new intent to specify the type of the settings activity that we want to open.
We want to open the notification settings for the watch movie channel.
Right.
So we're going to say cities with capital S dot on here we need to specify the type of the activity
settings the activity that we want to open.
The name is action.
So I'm going to just type it he had manually action underly channel action on the line
channel notification settings.
So this is the type of activity that we want to open.
Action channel notification settings.
But we must specify that we want to open the notification channel of the watch movie actually channel.
So if we are going to specify some extras for this intent.
So first we're going to send the package the package name of our application to this intent because
you want to specify that this is our application and we want to open the notification channel for our
own application.
So we are going to say setting's intent that puts extra.
And here we need to specify the name or the key into say sittings with capital as that extra package
come on and we need to send the value into past the actual value.
So if you're going to just say just package any
package simply call the Vini to send and other extras going to the settings intent that put extra sittings
settings that extra channel Id come on.
So here we already created a prime meter for this watch movie channel ID.
So let's change the name of this primetime to watch movie channel ID.
And then here we just need to pass it as an argument to this put extra effort.
So we just say watch movie channel ID and then we are going to actually say start activity and we just
passed the internet settings.
Intent OK.
So now we need to scroll through it so you can see that these are created if you already created an
unexpected close enough for this PTEN movie City movie settings button and inside this enclave we have
a case for this one for this between movie settings.
So we are going to just call this Meffert open notification settings for watch movie channel and we
just need to pass the ID.
The ID is notification handlers so we are referring to this question handler class.
And if you remember this notification handler class we actually declared this ID as static.
Right.
This means that by just accessing the notification class we can access this constant because it is public
static.
So it is a class variable or a constant thats going to say this may not have the class.
And here we say notification handler that I just got a token here ID and here it is the watch moving
notification channel ID.
So let me create a new line here so that we can see what's going on here.
Let's run the app and let's see what's going to happen.
So we just need to enter the name of the movie.
So we just see Star Wars and here I'm going to first I'm going to test that positive action for movie
works.
So it works.
You can see literally kind of settings for a movie for movie notification.
And here it is the settings for this application.
Here it is the name it is on importance.
We have urgent high medium low and we have a vibrate.
We have advanced notification.
So that's it.
Our application works fine and perfectly.
So I think that's enough for the story all in in the next application the next tutorial we're going
to start creating another app about notifications.
But this time our application is going to target versions before the Android 8 or Orio.
And you're going to see how it is implemented.
And again if you want to create your own application inside your app you should differentiate between
the Android API eyes before Android 8 and the Android 8 or above.
If you want to learn about a differentiating API using Android you can actually take a look at the some
of the applications that you have created in this course.
The one that I remember now is the floating view application that I actually uploaded into the section.
I think the last section of the course the name of the section is requested apps.
So thank you very much for watching.
If you have any questions about these concepts that I've taught you so far please post a discussion
in the course and then I will do my best to answer all of your questions.
And I look forward to seeing you in the next tutorial.