WEBVTT

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

00:00.920 --> 00:05.640
In this video we're going to learn how to request location permission from the user.

00:05.640 --> 00:11.280
So this is a very important step that is critical for location updates.

00:11.320 --> 00:13.080
Open this package.

00:13.080 --> 00:15.080
Create a new package.

00:15.120 --> 00:17.240
Name it as location.

00:17.240 --> 00:26.840
Inside this location, create a new Kotlin file and name it as location permission handler.

00:26.960 --> 00:32.120
Inside this class, I'm going to create a new composable function.

00:32.120 --> 00:35.160
Name it as request location permission.

00:35.160 --> 00:44.920
That takes two parameters the map view model and on permission granted, which is the lambda expression.

00:44.920 --> 00:47.080
Start with val.

00:47.120 --> 00:56.360
Location permissions equals to remember multiple permission state and inside it create permissions.

00:56.360 --> 01:02.080
List of file location and access course location Alt+.

01:02.080 --> 01:06.360
Enter to import the manifest from Android and Alt+.

01:06.360 --> 01:07.960
Enter to import the function.

01:08.000 --> 01:09.360
And here we go.

01:09.520 --> 01:17.290
This code creates a state holder that manages multiple runtime permissions specifically for location

01:17.290 --> 01:17.810
access.

01:17.810 --> 01:25.250
Both fine and coarse tracks permission status reactively and handles permission requests.

01:25.290 --> 01:33.610
A compose utility, which is remember multiple permission state function that remembers permission state

01:33.610 --> 01:35.290
across Recompositions.

01:35.410 --> 01:42.850
Providing current permission status methods to launch permission requests and automatic recomposition

01:42.850 --> 01:45.730
when permissions change access.

01:45.770 --> 01:54.570
A fine location GPS level accuracy 5 to 50m required for precise location tracking and coarse location.

01:54.570 --> 01:59.130
Network based accuracy from 100 to 500m.

01:59.170 --> 02:01.970
Less precise, but more battery friendly.

02:01.970 --> 02:06.130
So this is for more accurate location.

02:06.130 --> 02:15.890
And this is for low or network based accuracy, or less precise than more than the fine location and

02:15.890 --> 02:17.570
more battery friendly.

02:17.610 --> 02:25.380
Okay, the location permission object provides these important members, so all permissions granted

02:25.380 --> 02:29.340
permissions and launch multiple permission requests.

02:29.380 --> 02:32.380
That triggers system permission dialog.

02:32.500 --> 02:39.420
So for this, create a launched effect location permissions dot.

02:39.460 --> 02:41.940
All permissions are granted.

02:41.940 --> 02:50.620
If all permissions are granted, then go and check if location permissions dot all permissions granted.

02:50.820 --> 02:57.300
What we need to do we need to call ViewModel has location permission dot value.

02:57.340 --> 03:02.900
Set it to true to true and on permission granted.

03:02.940 --> 03:10.140
Otherwise what we need to do, we need to request permissions if not granted.

03:10.140 --> 03:15.420
So location permissions dot launch multiple permission request.

03:15.460 --> 03:15.980
Okay.

03:16.380 --> 03:18.980
So this will be executed once.

03:18.980 --> 03:26.140
So if the location is granted go and set the has location permission that value variable to true and

03:26.140 --> 03:28.020
execute all permission granted.

03:28.060 --> 03:33.380
Otherwise go and create and launch multiple permission requests.
