A free video tutorial from Atil Samancioglu
4.7 instructor rating • 24 courses • 254,615 students
Learn more from the full courseKotlin for Android O Development: From Beginner to Advanced
Learn coding and designing Android apps with Kotlin while building real app examples like Instagram and Foursquare clone
15:36:40 of on-demand video • Updated October 2019
- By the end of our course, you will be able to create professional applications and submit them to the play store from scratch!
- You will also have the skills of a professional developer who can earn thousands of dollars creating applications
English [Auto] Now if you remember working with permissions we have to first go to manifest as we have created this activity that Google Map activity. It already has a line for us access fine location and for any reason if you don't see this line you have to add it yourself. So use permission access fine location. It has to be there in order to work but it doesn't. And with this simple line we have to explicitly check to see if we have permission. So how do we do it. It is very similar to the external storage that we have seen in the previous section. So you say contex compact dot check self permission and the permission that we're going to check check is the contacts tax is this and the permission is actually permission dot you have to type it like this. So many firsts. OK. So let's import this. This one android men first got permission duct access fine location. So we checked to see if this is not the case that we have just Burma-Shave. So package manager not permission granted. So you open that coding block too. Right. What happens if this condition hopes so if we don't have this permission what do we do. Of course we just ask for it. OK so activity compact that request permissions and the remember'd ask for ID. So this and it asks us an array of permissions. So you have to create an array even though we have only one permission to ask. So this will be an array of permission and the permission that we're going to ask is manifest not permission not access fine location. And we have to deal with that request code just to identify it later on. So I will just type one and if we don't how does permission we will ask it and else as if we haven't already. What do we do. It means that we have access to our location service. Right. So I will just type location manager that request location updates and ask me some parameters again first of which we have to say it will be location manager that GPA is provided. So this is the pro-White. So this is the interval that we want to check the location. So if you type zero here it will check the location constantly. And if you type zero here it will check the location within the thing just a few inches of differences in distance. And finally you have to provide the location listener and it asks you to make this location manager nullable or with exclamation points. So I have to force him up this. And if you just type 0 0 it will be most accurate but it can drain your battery. OK. So I will just say two and two half and it will be more than welcome for me. OK. And next thing to do is to move the camera to the location here. OK. So let's copy this and paste it in here. OK. So since we have now requested the user's location now we can just move to the location. But in here we have used the previously known location or we have used the on change location. That's right. So this is valid then the location changes because location is given to us. Alice tried this actually and see what happens. And we can just write the code later on. So let's start these into our emulator. And as you can see it asks for permission. What will happen if I add Lovat nothing will happen since I didn't write anything regarding this. OK so let me show you this way you can just open your emulators advanced settings by clicking on this tree. That's OK. And let's say ok to this and let me bring my emulator next to it. How do you how do latitude and longitude of your simulated location. I will just change this latitude and longitude to somewhere nice like our Amsterdam example here. OK. So latitudes will be this let me copy it again. OK. And longitude. This one. So let me paste it in here and say sense. OK so that I change my user location. OK so let me close this down and let me just play this from the beginning. And later on maybe I will be able to see my location. Here we go. Now I see my location k. And if you click on it it says your location. So what happened when we first opened the emulator right why couldn't we see our location. It actually came here and sneaked for permission and it couldn't find. So it asked for permission but we didn't do right. What will happen if users do use permission. So nothing got cold. We didn't even request the location update. OK we didn't request any location from system so we couldn't see anything but we later on actually opened that from the beginning and then we got the permission and it found our location. So let's stop here and continue within the next lecture.