WEBVTT

00:00.080 --> 00:00.920
Welcome back.

00:01.160 --> 00:05.680
The first step in getting the current location is to create the variable.

00:05.680 --> 00:10.400
It's of type location and it's of mutable state.

00:10.640 --> 00:15.760
Now the second step is the location permission launcher.

00:15.960 --> 00:20.080
Start with val location permission launcher.

00:20.200 --> 00:27.960
Remember launcher for activity result activity result contracts dot request permissions.

00:28.240 --> 00:30.960
Let me explain what we create here.

00:31.200 --> 00:39.640
This line creates a permission launcher using jetpack composes integration with the Activity Result

00:39.680 --> 00:40.280
API.

00:40.640 --> 00:47.960
It will be used to request the location permission at runtime, for example access, find location and

00:47.960 --> 00:49.080
other permissions.

00:49.280 --> 00:57.880
Since the location getting current location of the user demands and request many permissions like access,

00:57.880 --> 01:06.840
file location and course location, we need to check that the user enable or enables the location or

01:07.000 --> 01:07.760
not.

01:08.080 --> 01:17.080
Okay, so this is the main purpose of this code to check if the user enable remember launcher for activity

01:17.080 --> 01:17.800
result.

01:17.840 --> 01:24.640
This is a composable function that creates and remembers an activity result launcher.

01:25.030 --> 01:33.390
it allows you to launch permission requests or other activities and handle the result in a callback.

01:33.670 --> 01:37.150
It survives recompositions automatically.

01:37.270 --> 01:41.030
You don't need to reinitialize it every time.

01:41.110 --> 01:42.630
Activity result.

01:42.910 --> 01:45.550
Contracts dot request permission.

01:45.670 --> 01:52.750
This is a contract for requesting a single time or single runtime permission.

01:52.790 --> 01:59.270
Android will show the system permission dialog and return a boolean result.

01:59.470 --> 01:59.990
True.

02:00.190 --> 02:01.550
Permission granted.

02:01.550 --> 02:02.230
False.

02:02.230 --> 02:03.990
Permission denied.

02:04.030 --> 02:14.230
Okay, so let me start by requesting a location and if it is granted, get the current location is granted.

02:14.230 --> 02:24.190
So if it is true then what we need to do we need to call a function called fetch current location.

02:24.190 --> 02:32.350
So here in this video we learned about activity result contracts and remember launcher for activity

02:32.470 --> 02:33.390
result.

02:33.510 --> 02:42.750
Here we are requesting from the user to grant the permission and if it is granted, we need to fetch

02:42.750 --> 02:44.310
the current location.

02:44.310 --> 02:50.150
In the next video we're going to create this function to get the current location.
