Hello everyone.
So it is the story I want to tell you that because we want to access the user's location we want to
we need to actually to first ask for the permission.
So it's very important that first we must actually ask for the parent permission because we want to
access the use that it's location and it is actually called a dangerous permissions so we must ask.
First of all we need to actually put that permission inside the manifest file so that I should add that
up just click on View and then tool windows and that we can project.
So as you can see the shortcut for the match is comment 1 if you are using a Windows machine the shortcut
should be must be different.
So I think it is actually control one.
So just click on it.
So here let's actually open the app folder here and then let's double click on this manifests here.
If you don't have this manifest file here you just to open this folder and it is actually the object
manifesto and fight.
So let me double click on this tab and write manifested XML.
So inside this android manifested exemplified here after the ending tag of this manifest and before
the ending.
Or should it be for this application.
I would actually put these permissions here which is open attack and just type in here use is permission
and the name is going to be course location and access course location.
So what is this permission.
It is actually that the permission that is going to give us the location actually the approximate location
of the users device.
OK.
So the course of course location is going to give us the approximate location.
We have another location called Falling location.
So it is the final location is a little bit more actually exact it is more precise.
But the problem with accessing a final location is that it going to actually eat more battery.
So we are going to stick with this one access course location is actually enough for this application.
It's going to just give us the approximate location.
So let's put up a slash and the end in type in order to actually close the stack here.
So that's it.
And now we need to actually at the meditator.
OK so let's see how we can do that.
So now you may ask that so why we have to add them to the top because we need to tell the Andray manifest
that we are going to use the Google Play services.
So it is very important that we at the Met at 8am.
So after you can see this application Typepad here right it is actually their starting.
And it is the ending tag here.
Right.
So after this starting tag and before these activities here.
OK.
I created some space.
Here it is the place actually to add the metadata.
So just open it and just typing here Mr. data.
And then here let's actually create a new line here let me create on your line and just type in here
actually name and inside the quotes here.
Just type in here come that Google dot Android dot GM s dot version.
OK that version.
And then here as you can see we added this name here right.
You need to actually add another value here and it is actually called value.
So just type in here value and here this is value right so inside the quotes instead of course just
typing here at sign integer and just typing here.
Google Play services version.
So the autocomplete feature of Android studio is going to help you to choose this one so just pleasant
person on your keyboard and in order to end this tablet you're going to self-closing this like right.
I just need to put on slash here and here you can see that the Android to do you put this into here
for me automatically.
Right.
So this is our metadata.
And here I want to specify that this application is going to be used only in portrait mode not in landscape
mode but only in portrait mode so how we can do that.
So here you can see it is actually activity tach right.
This is actually distorting Tadg.
So here it says android named main activity.
Let's actually create our space here and here just type the screen orientation screen orientation and
just choose portrait's right.
So now here we are telling the activity that this activity here main activity is going to be only used
in portraits mode not in landscape mode.
OK.
So that's it.
And now we actually added all the codes that we needed for now.
OK so far we've added all the cards that we needed here to these and manifest why.
So now it's time to go to the main activity class and here you can see these fits right.
Right.
So now I'm going to actually create a new method inside these main activity and inside this man I can
declasse actually so at the top of the bottom of the fight after the ending curly brace of this on can
action fake.
I'm going to create m if I want to create a comment here that says I should custom if it's like a custom
methods.
So the custom effects are the methods that I actually added myself.
OK.
So let's put these Misfit's here below this comment.
So because we are going to use this method only inside this main activity class we can actually declare
RMF as private for now.
OK.
Later we may want to actually to change this access modifier.
But for now I just want to use this method inside this main activity class so private and return type
of this method is going to be void and the name of this Smurfette is going to be actually show the user
location write and put up that apprentices this movie is not going to accept any prime interest and
just open and close the Smurfit by using these curly braces.
So inside this method first we need to actually ask the user in order to give us the permission in order
to access the location.
OK.
So it is called runtime permission.
We must ask the user because it is actually necessary.
It is called A Dangerous permission.
In Android to access the user's location so the user must be actually aware of that permission.
So it is called a runtime permission.
So let's see how we can do that.
First let's create a variable of type in teacher and the name of this variable is going to be permission
check permission check and put an assignment operator here and just type in here context compacts that
check self permission.
First if it actually accepts two arguments the first one is the context.
So the context is main activity right because the main activity is going to actually access the location.
So main activity that this is the context the comma the second argument is going to be the actual permission.
So because we want to access the user's location the users approximate location actually I'm going to
just type in here and manifest that permission.
That just they've been here.
Course we've chapiter c course location.
So it's going to put the actual name here automatically for us and then put a semicolon at the end of
this statement.
So let me ask you to create a new line here so that you can see these values.
So as you can see if we create that are valuable if that is your permission check and we assign this
value to this valuable context compact that checks of permission.
And as the arguments first.
We need to pass the the context.
And the second argument is going to be the actual location.
So this code here is going to actually return a value of that material and it's and it is going to be
assigned to this body of it.
So now I can create an if statement right.
I can actually say if permission check is equal to package manager that permission granted.
So as you can see I need to put a capital P in order to actually see the autocomplete feature ID or
to complete the options here.
So it was permission granted.
So this means that if their permission to value is equal to the Permission granted here this means that
the user has actually gave us their permission to access the location right.
In that case we can actually open and close this method by using the curly braces.
So let's create an else statement here.
LS So else means what else means that this expression he had evaluated to false.
So now it is going to execute this else it's.
So in that case if this condition is false and the user actually denied to access the location the right
to access the location in that case you are going to execute this statement.
So here I can't just CTX the location that a said text and I can just put two codes here and here I
can say this app is not allowed to access the location.
Right.
So this is the else statement and that is actually to go inside this.
And so this means that the user has actually gave us that the actually the permission so we can actually
put the quotes here.
But inside this Elsa's statement.
Let's add another quote here it is.
This means that the user is not actually doesn't allow us to access the location right.
So we can actually ask the user we can actually create our requests here in order to ask the user to
give this application the permission to access the location.
So let's see how we can do that.
So I'm going to paste this line of code here and then I'm going to explain to you what's going on here.
Exactly.
So as you can see I actually pasted this line of code here.
It says activity compact that request permissions.
So it is going to actually actually create a request.
I was going to ask the user to access the location.
First we need to pass the context main activity that this come up.
And the second argument is this one new stream.
So here it is going to create the paramecia right streamed.
It is actually an array right new An at a upstreams.
And as the first value of this.
Here we are going to pass this value inside the curly braces manifest that permission that access course
location come up here and it is actually to devalue number one here so what is this value let me actually
just again type this out here again.
So the first value is activity Compaq's write activity compact that request permissions.
So let me tell you this is actually the request code.
Ok the first argument is the request code.
So here I just this is actually just a simple request right.
So I just passed the value.
Number one if you want to you can actually change it to any other values or you can just create a constant
for this value but it is just a simple request or just past the value number one.
OK.
So make sure that it is actually a unique value that you are not using inside your application.
So number one is not use the inside for that application.
So I just pass on to that number one here.
So now we can go inside this statement.