So now that we have the Smurfette actually does show the use of location here we need to actually call
it from these unconnected method here.
So let's go inside the curly braces of this unconnected method and here I just need to type in here
show the user location and let's actually also lock some values here.
So just type in your log that's the and then actually the.
And then just put a pair of parentheses first.
We need to actually pass the tach.
So we already created a value of type tags inside this main activity class to just put that here.
And as the second argument we can actually just put two quotes here and we can say connected.
Or we can say we can.
We are connected.
To their users location users location.
Right.
Semicolon.
So that's it.
And now we have also these two methods of connection suspended.
So let's go inside this connection suspended method.
And here let's also lug some values so lug that the inside Apprentice's.
First we need to pass the pack come up and as the second argument I can just put two coats which is
a five string right.
And here I can see the connection is suspended.
The connection is suspended semi-colon and we have this method of connection failed.
OK.
So let's go inside the curly braces of this method.
So this method is going to be called when the connection is actually failed.
When the user is not actually able to get the location and the application is not able to get a location.
In that case it's going to this if it is going to be called on connection failed.
So let's actually lock somebody like that.
The as the first argument we need to pass the comma.
And as the second argument I can just pass this value.
The connection failed.
Right semicolon.
So let's create some if statements here inside the Smurfit.
So here first let me tell you that the user must have access to the Google Play services in order to
actually use the capabilities of this application in order to access their location.
OK.
So if the user cannot access to Google Play services or if the user is not signed in or if they use
that actually doesn't have any access to Google Play services.
In that case the connection may be fake.
OK.
So we don't actually check for that condition.
We want to prompt the user to actually sign in in Google Play services so that the user can actually
continue using this application.
First let me actually show you the emulator that the documentation actually.
So you can see this connection result class.
OK.
So first let me show you the Android studio and you can see that this method of connection failed actually
has an argument.
This parameter here.
Right.
And the data type of this argument is actually the connection result.
This is the connection result class.
So let's go to the documentation.
You can see this class and it says Puplick fine and class connection result.
Accent's object.
So this class extends the object class and implements the parsable actually interface right.
So let's actually look at this description it says contains all possible error codes for when a client
or client refers to the application that want to access them.
Actually the Google Play services our client fails to connect to Google Play services these error codes
are used by Google API client.
That connection failed listener.
Right.
So this is actually familiar to you.
So now let's actually go back to android studio here.
So we have these arguments right.
So let's actually to check for these kinds of errors.
OK.
Now I can't say if connections result that has resolution.
So this has resolution whether actually to return a value of a boolean.
So here I am actually fed into this connection result and I am accessing a method that is actually this
is actually an instance of this connection resolved has a resolution.
So let's go back to the under documentation and in and here let's actually search for has a resolution
method here.
Right.
So in order to test for a specific keyword here instead of a page if you are using a Mac you just need
to hold down the command key on your keyboard and then press and if key on your keyboard.
And if you are using a Windows machine you just need to hold down the control on your keyboard and then
press on if key on your keyboard.
So here I can search for has resolution resolution.
Right here it is.
It actually found free results here.
The first one is this one.
You can see it is public.
If it's somebody Paulian.
So the return type of this Mfat is boolean and it returns true if calling starts with resolution for
result will start any intense requiring user interaction.
So this means that it's going to actually give us if this method has resolution retains the value true.
Let me show you the Andrew studio here.
We are looking for the value to right.
Here we are saying that if the condition is that that has a resolution.
So because this is should return the a value of the bullion.
Here we are looking for that for the true value.
It is going to return the value true.
Let me show you the emulator then it's going to actually open and intent and other intent in order to
prompt the user to actually do for example signing to Google Play services or for example or just install
the Google Play services.
So that's what this has it has a resolution means.
OK.
It is actually true.
Then we can i should open and close dismiss this statement by using the curly braces.
I can't just referred to this argument connection result that start resolution for result.
OK.
And this left accepts two arguments the first one is the context.
Main activity that this and the second one is the request the court.
So it is an integer right.
We already have valuable of type integer.
This is actually a constant Let me show you that this constant here.
So here it is our request called Constant and we assigned the value 1000 to this constant right.
So we can use it here.
This is actually a unique value that we use for Google Play services in order to actually prompt the
user to sign in or to install the Google Play services under device.
So now if we actually call this method and the user would be able to sign in or do any necessary changes
to access the Google Play services then it is going to return true.
And the problem is going to be solved.
OK then it's not going to actually call this connection failed method again.
So let's pass this request here request called.
Right.
But here we had a problem.
OK.
So what is that problem hovered over this area.
It says unhandled exception and throughout that content that intent the sender that sent intent exception.
This means that the user's device may actually fail to for example open another intense and other activity
to prompt the user to sign into Google to Google Play services or install the Google Play services the
users device may actually fail to do that.
OK.
We need to handle that exception how we can do that by using to try catch block.
So just typing here try and put this line of code he had inside a try block just cut and paste it here
and then it'll handle that exception.
So after the end curly brace of this try block I can just say catch an inside Apprentice's I can say
acception.
OK.
So this is the name of this argument actually and I just want to open and close this terrible act by
using these curly braces.
And here I can't just say lug that D.
And first I need to pass the patch comma.
And here I can see that description excuse me it that stack get stack trace to strings.
OK semicolon.
So it can actually print some values to the log and then we can actually see what's wrong.
OK.
So that's it.
We actually handle the exception.
So this is our IF statement.
OK so now after the end in curly brace of this if statement let's actually create an illicit statement
so this is this statement is going to be executed if this condition actually face.
Ok if this condition here evaluates to false and the user would not be able to access the Google Play
services in that case we want to actually finish what those finished means.
Finish means exit the application completely.
The user is not is not going to be able to use this application anymore if the user is not able to access
the Google Play services.
So we put this as a statement and here first I can't say toast does it make text.
First we need to pass the context main activity that this come up.
And as the second argument we need to pass the value so I can say Google Play services Google Play services
is not working.
OK.
Backseats come up.
And as the second argument we need to specify the duration of the message that I want to show to the
users so it is going to be actually Laune that show.
That's it.
And then here I am I'm just going to call Finish finish means actually is going to finish.
It's going to go outside of this.
I mean it is going to close this main activity and then it's going to actually finish using this app.
So that's it.
Now.