May 2021 update: For those having trouble with location permissions on API 30 or higher, here is a solution. Within requestPermissions(), on the third if() statement regarding background permissions, change the code to: if(!hasLocationBackgroundPermission() && hasLocationForegroundPermission()) In this case, the button must be clicked twice to request background location permissions. (I'm sure there's a more correct way to implement this, but this is an easy way to correct the problem in this case). To learn more why this works, look up "Request location permissions" in the Android Developer documentation. There is a statement that says requesting foreground and background permissions at the same time will be ignored. Furthermore, background permissions will not be granted unless foreground permissions were previously granted.
Hello There is one more way to done it using single click only just add this code again in onRequestPermissionsResult permissionToRequest.clear() if (hasForegroundPermission() && !hasBackgroundPermission()) { permissionToRequest.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION) } if (permissionToRequest.isNotEmpty()) { ActivityCompat.requestPermissions(this, permissionToRequest.toTypedArray(), 0) }
Hey Philipp, I love your videos. I just wanted to point out that this workflow is (sorta?) deprecated according to the documentation. I'd love to see an updated video covering the new paradigm. I've been trying to wrap my head around it, and was kind of disappointed you don't have a more recent video on this, since you're who I turn to to clarify stuff like this! In any case, keep up the great work. Loving the newer Compose content.
Hey , why is it sorta deprecated? Are you referring to the fact that he is not using shouldShowRequestPermissionRatinonale()? Is the rest of his code good for use?
@@isown8131 It's more that there are more modern APIs to manage permissions. For the most part, it's still a great video. I don't remember the specific thing I had problems with.
I would also love this. I just ran into the message `getSerializedExtra` is deprecated and the alternative (passing the class as a param) is also not working.
Hi, Philipp, thanks again for your awesome content! Can I ask why at 11:10 you specified that in this case "Make sure you use ActivityContext instead of ApplicationContext"? Still confused about when to use ActivityContext or ApplicationContext
Hi phillip i could really understand about every video you've put into work. But there's one that still confused me. Why we use hasWriteExternalStorage with "function (private fun)" instead of "variable (var/val)" Please help if someone could give an explanation. Thankyou
I think it might be because a function definitively gets called when you invoke it (and only then assigns a value to the expression you mentioned) whereas a variable gets assigned wherever in the code you write it. You can't "call" a variable to recheck whether the value of that expression has changed, you'd just have to rewrite the variable or expression all over again any time you'd want to recheck if it has changed. That's my understanding of it anyway. I could be totally off the mark.
I want to say a big thanks Philipp. Your videos have a very easy-to-grasp logic and have been a big help with my studies. I would like to request if you could make an update on the permissions video. When I follow the session after launching the app, it does not show the request to accept permissions.
Nice Video Sir, How to handle when user again click "deny and Don't ask again" . I prefer open device permission setting on the basis of result of onRequestPermissionResult. Please guide ??
OK but this doesn't explain at all when you should request the permissions, what to do once you've gotten them, when yo might need to request them again or anything about how permissions work in the context of a full Android application
Hi Philipp, Great video once again. Could you please create one more video showing how to use new Activity Contract API for requesting permissions and handling denying and rejections. Thanks in advance,
Hi Phillip, thanks a lot for your tutorials, they are great. I am having problem with this part though, I've done everything you did but Im not getting the Permission prompt after clicking a button, nothing happens. I am using API 30 (Pixel 2) - could that be a problem? Thanks a lot
It is not working on A11 like the pop up for asking for permission is not showing up at all on clicking button, the log says button was clicked but nothing regarding the permission while the app works properly on A10 or below
@@betaaccount7450 you are right! thanks! also tried A C's suggestion, it works too: if(!hasLocationBackgroundPermission() && hasLocationForegroundPermission())
Sir i visited your site to buy android course unfortunatly i can't effort. I'm working as a Mobile App developer only for 120$ per month. Sir if you have any scholor program please let me know. Btw thank you for you high quality tutorials.
what is the difference between dexter permissions and android default permissions is dexter more powerfull then the default android permissions and will this code run with android 11 as well?
suddenly i am thinking if i can convert manifest file into JSON object then maybe i can do something with it using javascript.. does xml code being compiled/ parsed into java byte code? is there a way of asking permission using kotlin (programmatically) and not xml is xml secure?
If your app targets Android 10 (API level 29) or higher, remove the ACCESS_BACKGROUND_LOCATION permission from your app's manifest. When you remove this permission, all-the-time access to location isn't an option for the app on devices that run Android 10.
hey, the = is there because 'hasWriteExternalStoragePermission' returns a single Int value and because of that, it can be written like this. This is how single expression functions are described in documentation: Single-expression functions When a function returns a single expression, the curly braces can be omitted and the body is specified after a = symbol: example: fun double(x: Int): Int = x * 2
Same here, but I believe that is due to API change. I understand the concepts, just need to practice what the documentation states. So I plan on recreating this after I finish the complete playlist.
If the API your phone or emulator uses is past 29 this tutorial is slightly outdated. I think when it comes to requesting location you can still use almost the exact same format the video uses but you can't request background location and foreground (course or fine) location at the same time like he does. You need to first request foreground location and once that has been accepted you can seperately request background location. Try commenting out the request for background location alltogether and this video should still work and will get you a permission prompt asking if you'll accept the app using foreground location.
Here in HAS functions we use = sign ...not curly brackets ... I noticed If I put brackets and specify type explicit then == GrantPermission..... not works ...why ??
Very nice explanation , dear sir I have two questions 1. In my mobile this code only asks for COARSE_LOCATION and EXTERNAL_STORAGE but not for BACKGROUND_LOCATION I don't know why ??? 2. When I accept those permission my GPS location doesn't on , and also internet connection doesn't ON, Why ?? I have accepted those permission .
@@PhilippLackner sir I am from Varanasi , India , and I am a beginner but there is no one to help me , can I have your contact details so that I can ask you questions My gmail id is - himanshuseth.in@gmail.com Sir plz send me your email id so that I can ask questions plzzz.. Sir plz I am very interested in android development but no teacher I have
@@MCA_HimanshuSeth hello my Friend. Im hindi too :) Do not worry about my European nickname, it's just a simple trick so the youtubers answer my questions more often. @krzysztof is my mentor since 2019 and thanks to Him i recently got promoted from Young Junior Account Brand Manager to Young Junior Executive Account Brand Manager!! :) I am so grateful to this bright man!
@8:02 Bro how come you can compare Manifest.permission to PackageManager.PERMISSION_GRANTED?? is PackageManager an abstract class and so does it need to be implemented or inherited first?
Hey, I hope you already have the answer. If not, PackageManager is an abstract class (as you had surmised) but what we are comparing isn't PackageManager itself but a public static property within PackageManager itself. The property is an integer type and I suppose the checkSelfPermission method returns an integer, which makes both the PackageManager.PERMISSION_GRANTED and the checkSelfPermission comparable to each other. If you have never done Java, think of a static property like a companion object which you can use without actually creating an object of a particular class in Kotlin.
7:40 what do you think if i create a single function and just pass it the permission you want to check and it should return a boolean value like this: private fun hasPermission(permission:String):Boolean { return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED }
The Internet permission is not considered as a dangerous permission by Android. As such, you only need to declare it within your manifest file (it does not need user acceptance since it does not compromise your privacy).
Nice video as always!!! I have a question with this line: if(permissionsToRequest.isNotEmpty()) { ActivityCompat.requestPermissions(this,permissionsToRequest.toTypedArray(),0) } I dont understand well why you use ActivityCompat.requestPermissions(this,permissionsToRequest.toTypedArray(),0) Thanks a lot for such amazing videos
Android studio 2023 SUCKS big time. Slow, hogs all of your memory, task manager can't end process, downloads stuff and packages every time an app is being debugged andvryn, indexing tajes forever to finish, gradle jeeps downloading unneeded 💩💩💩packages Device manager can't launch virtual devicevor hookbup tova real one, and if successful the device would horribly display your layout.
Hey man, need some help, do you know why is this permission? I tried to remove it and run the app, did several tests and apparently nothing changed, but I am trying to understand why this permission is needed, thank you
May 2021 update: For those having trouble with location permissions on API 30 or higher, here is a solution.
Within requestPermissions(), on the third if() statement regarding background permissions, change the code to:
if(!hasLocationBackgroundPermission() && hasLocationForegroundPermission())
In this case, the button must be clicked twice to request background location permissions. (I'm sure there's a more correct way to implement this, but this is an easy way to correct the problem in this case).
To learn more why this works, look up "Request location permissions" in the Android Developer documentation. There is a statement that says requesting foreground and background permissions at the same time will be ignored. Furthermore, background permissions will not be granted unless foreground permissions were previously granted.
Hello
There is one more way to done it using single click only
just add this code again in onRequestPermissionsResult
permissionToRequest.clear()
if (hasForegroundPermission() && !hasBackgroundPermission()) {
permissionToRequest.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
}
if (permissionToRequest.isNotEmpty()) {
ActivityCompat.requestPermissions(this, permissionToRequest.toTypedArray(), 0)
}
Thank you for the explanation , it was really helpful .
please pin the above comment
That's my intern!
Hehe, it works now
Hey Philipp, I love your videos.
I just wanted to point out that this workflow is (sorta?) deprecated according to the documentation. I'd love to see an updated video covering the new paradigm. I've been trying to wrap my head around it, and was kind of disappointed you don't have a more recent video on this, since you're who I turn to to clarify stuff like this!
In any case, keep up the great work. Loving the newer Compose content.
Hey , why is it sorta deprecated? Are you referring to the fact that he is not using shouldShowRequestPermissionRatinonale()? Is the rest of his code good for use?
@@isown8131 It's more that there are more modern APIs to manage permissions. For the most part, it's still a great video. I don't remember the specific thing I had problems with.
I would also love this. I just ran into the message `getSerializedExtra` is deprecated and the alternative (passing the class as a param) is also not working.
I gotta add, best Android permissions video currently.
Very very cool. Very local, as if everything was gradually assembled, the first I see this. You are younger !!! Good luck, thanks for the content !!!
Thanks for the feedback!!
Its awesome dude, keeping up make more videos, because its very useful for us to learning fundamental to expert android, love from Indonesia
Thanks a lot, I will!
@@PhilippLackner Terima Kasih Pak Philip = Thank you Mr.Philip :)
This was quite the video man. Almost didn't understand it but I did it!! I understand this subject at last.
so confusing man!! :0
edit:
i've watched it like 5 times .............now i understand :)
thank you so much Pal
very precise and complete at the same time, thank you Philipp
That permission dialog box is not showing for me
Hi, Philipp, thanks again for your awesome content!
Can I ask why at 11:10 you specified that in this case "Make sure you use ActivityContext instead of ApplicationContext"?
Still confused about when to use ActivityContext or ApplicationContext
u always spot on with ur explanations...thank you Phillip
Hi phillip i could really understand about every video you've put into work. But there's one that still confused me.
Why we use hasWriteExternalStorage with "function (private fun)" instead of "variable (var/val)"
Please help if someone could give an explanation. Thankyou
I think it might be because a function definitively gets called when you invoke it (and only then assigns a value to the expression you mentioned) whereas a variable gets assigned wherever in the code you write it. You can't "call" a variable to recheck whether the value of that expression has changed, you'd just have to rewrite the variable or expression all over again any time you'd want to recheck if it has changed.
That's my understanding of it anyway. I could be totally off the mark.
I want to say a big thanks Philipp. Your videos have a very easy-to-grasp logic and have been a big help with my studies. I would like to request if you could make an update on the permissions video. When I follow the session after launching the app, it does not show the request to accept permissions.
Okay, so I just read most of the permissions used are for android 10 and below.
Nice Video Sir, How to handle when user again click "deny and Don't ask again" . I prefer open device permission setting on the basis of result of onRequestPermissionResult. Please guide ??
Dexter is useful to manage multiple permissions , which is better ?
this code will only work for API
I do have up to date videos about permission handling
@@PhilippLackner yes pls do this
thanks bro.. from india
OK but this doesn't explain at all when you should request the permissions, what to do once you've gotten them, when yo might need to request them again or anything about how permissions work in the context of a full Android application
Awesome! 👍
Thanks! 👍
Very cool Philipp!
Hi Philipp,
Great video once again.
Could you please create one more video showing how to use new Activity Contract API for requesting permissions and handling denying and rejections.
Thanks in advance,
Hi Phillip, thanks a lot for your tutorials, they are great. I am having problem with this part though, I've done everything you did but Im not getting the Permission prompt after clicking a button, nothing happens. I am using API 30 (Pixel 2) - could that be a problem? Thanks a lot
Probably you miss the "!" sign in if statements in "requestPermissions" function
I'm having the same problem
same problem
@@陈大锤-q1s me too
me too
It is not working on A11 like the pop up for asking for permission is not showing up at all on clicking button, the log says button was clicked but nothing regarding the permission
while the app works properly on A10 or below
having the same problem here, unfortunately
@@51bpegasi actually do one thing ask for foreground location only
Asking both at same time cause pop up to get rejected by system on A11
@@betaaccount7450 you are right! thanks!
also tried A C's suggestion, it works too: if(!hasLocationBackgroundPermission() && hasLocationForegroundPermission())
You are King.
Sir i visited your site to buy android course unfortunatly i can't effort. I'm working as a Mobile App developer only for 120$ per month. Sir if you have any scholor program please let me know. Btw thank you for you high quality tutorials.
what is the difference between dexter permissions and android default permissions is dexter more powerfull then the default android permissions and will this code run with android 11 as well?
suddenly i am thinking if i can convert manifest file into JSON object then maybe i can do something with it using javascript..
does xml code being compiled/ parsed into java byte code?
is there a way of asking permission using kotlin (programmatically) and not xml
is xml secure?
You are amazing thanks a lot
How to analyze in Androidmanifest.xml file mentioned permissions are required for the application? It means how to find unwanted permissions ?
If your app targets Android 10 (API level 29) or higher, remove the ACCESS_BACKGROUND_LOCATION permission from your app's manifest. When you remove this permission, all-the-time access to location isn't an option for the app on devices that run Android 10.
Why there is '=" sign in front of that function? Thanks for AWESOME content
hey, the = is there because 'hasWriteExternalStoragePermission' returns a single Int value and because of that, it can be written like this. This is how single expression functions are described in documentation:
Single-expression functions
When a function returns a single expression, the curly braces can be omitted and the body is specified after a = symbol:
example: fun double(x: Int): Int = x * 2
@@hxrin3748 oh oh thanks got it 👍
Whenever i create app with internet permission it only works when installed from android studio.Not as apk why so?
Thank You
No Permission prompt after I press the button. Can somebody help?
Same here, but I believe that is due to API change. I understand the concepts, just need to practice what the documentation states. So I plan on recreating this after I finish the complete playlist.
@@rowenarrow did you figure out?
If the API your phone or emulator uses is past 29 this tutorial is slightly outdated. I think when it comes to requesting location you can still use almost the exact same format the video uses but you can't request background location and foreground (course or fine) location at the same time like he does. You need to first request foreground location and once that has been accepted you can seperately request background location. Try commenting out the request for background location alltogether and this video should still work and will get you a permission prompt asking if you'll accept the app using foreground location.
Here in HAS functions we use = sign ...not curly brackets ... I noticed If I put brackets and specify type explicit then == GrantPermission..... not works ...why ??
Very nice explanation , dear sir I have two questions
1. In my mobile this code only asks for COARSE_LOCATION and EXTERNAL_STORAGE but not for BACKGROUND_LOCATION
I don't know why ???
2. When I accept those permission my GPS location doesn't on , and also internet connection doesn't ON, Why ?? I have accepted those permission .
Background location is only for API 29 (android Q)
I don't get your second question
@@PhilippLackner sir I am from Varanasi , India , and I am a beginner but there is no one to help me , can I have your contact details so that I can ask you questions
My gmail id is - himanshuseth.in@gmail.com
Sir plz send me your email id so that I can ask questions plzzz..
Sir plz I am very interested in android development but no teacher I have
@@MCA_HimanshuSeth i can be your mentor
@@MCA_HimanshuSeth hello my Friend. Im hindi too :) Do not worry about my European nickname, it's just a simple trick so the youtubers answer my questions more often. @krzysztof is my mentor since 2019 and thanks to Him i recently got promoted from Young Junior Account Brand Manager to Young Junior Executive Account Brand Manager!! :) I am so grateful to this bright man!
@@krzysztoffarys7189 how can I contact you ?
Pls how to open permission for data collector of code on Android studio
How to enable location services in WebView...?
Do notifications need permissions?
@8:02
Bro how come you can compare Manifest.permission to PackageManager.PERMISSION_GRANTED??
is PackageManager an abstract class
and so does it need to be implemented or inherited first?
Hey, I hope you already have the answer. If not, PackageManager is an abstract class (as you had surmised) but what we are comparing isn't PackageManager itself but a public static property within PackageManager itself. The property is an integer type and I suppose the checkSelfPermission method returns an integer, which makes both the PackageManager.PERMISSION_GRANTED and the checkSelfPermission comparable to each other. If you have never done Java, think of a static property like a companion object which you can use without actually creating an object of a particular class in Kotlin.
You're OG!
7:40
what do you think if i create a single function and just pass it the permission you want to check and it should return a boolean value like this:
private fun hasPermission(permission:String):Boolean {
return ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
}
What about internet permission?
The Internet permission is not considered as a dangerous permission by Android. As such, you only need to declare it within your manifest file (it does not need user acceptance since it does not compromise your privacy).
why not able to android R this permission?
Will this code work for android 11?
my brain:Lord's mercy
Nice video as always!!! I have a question with this line:
if(permissionsToRequest.isNotEmpty()) {
ActivityCompat.requestPermissions(this,permissionsToRequest.toTypedArray(),0)
}
I dont understand well why you use ActivityCompat.requestPermissions(this,permissionsToRequest.toTypedArray(),0)
Thanks a lot for such amazing videos
he explains it in the video
I knew it, you are german. Me too :D
Android studio 2023 SUCKS big time.
Slow, hogs all of your memory, task manager can't end process, downloads stuff and packages every time an app is being debugged andvryn, indexing tajes forever to finish, gradle jeeps downloading unneeded 💩💩💩packages
Device manager can't launch virtual devicevor hookbup tova real one, and if successful the device would horribly display your layout.
too complex. start with one permission.
Hey man, need some help, do you know why is this permission?
I tried to remove it and run the app, did several tests and apparently nothing changed, but I am trying to understand why this permission is needed, thank you
can some one help me out after the activtyCompat(....)==packageManager.PERMISSION_GRANTED for me the PERMISSION_GRANTED IS NOT SHOWING??
"PackageManager" not "packageManager". That's probably your mistake as well as anyone else who has the same problem.
my button part at the end isnt working