PERMISSIONS - Android Fundamentals

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

Комментарии • 94

  • @s-w
    @s-w 3 года назад +59

    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.

    • @kartikagarwal1795
      @kartikagarwal1795 3 года назад

      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)
      }

    • @younesboulghobra
      @younesboulghobra Год назад +1

      Thank you for the explanation , it was really helpful .

    • @billmolloy2264
      @billmolloy2264 Год назад +1

      please pin the above comment

    • @chasebrown8011
      @chasebrown8011 Год назад +1

      That's my intern!

    • @mayank_upadhyay_19
      @mayank_upadhyay_19 4 месяца назад +1

      Hehe, it works now

  • @b4ux1t3-tech
    @b4ux1t3-tech 2 года назад +9

    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.

    • @isown8131
      @isown8131 2 года назад

      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?

    • @b4ux1t3-tech
      @b4ux1t3-tech 2 года назад

      @@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.

    • @JoeSteele
      @JoeSteele Год назад

      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.

  • @matt-g-recovers
    @matt-g-recovers 3 года назад

    I gotta add, best Android permissions video currently.

  • @НиколайТурьев-ж9р
    @НиколайТурьев-ж9р 4 года назад +2

    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 !!!

  • @fuadydheo3155
    @fuadydheo3155 4 года назад +7

    Its awesome dude, keeping up make more videos, because its very useful for us to learning fundamental to expert android, love from Indonesia

    • @PhilippLackner
      @PhilippLackner  4 года назад +3

      Thanks a lot, I will!

    • @gezafiqrullah5321
      @gezafiqrullah5321 4 года назад

      @@PhilippLackner Terima Kasih Pak Philip = Thank you Mr.Philip :)

  • @TheImaginativeSachin
    @TheImaginativeSachin 2 года назад

    This was quite the video man. Almost didn't understand it but I did it!! I understand this subject at last.

  • @code_sorcerer123x
    @code_sorcerer123x 4 месяца назад

    so confusing man!! :0
    edit:
    i've watched it like 5 times .............now i understand :)
    thank you so much Pal

  • @shivtiwarii
    @shivtiwarii 7 месяцев назад

    very precise and complete at the same time, thank you Philipp

  • @devprasad8767
    @devprasad8767 2 года назад +4

    That permission dialog box is not showing for me

  • @nervous711
    @nervous711 2 года назад +5

    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

  • @titusnangi8586
    @titusnangi8586 2 года назад

    u always spot on with ur explanations...thank you Phillip

  • @charlesschen1292
    @charlesschen1292 2 года назад +5

    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

    • @broma3974
      @broma3974 Год назад +2

      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.

  • @emmanuelekowacquah155
    @emmanuelekowacquah155 Год назад

    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.

    • @emmanuelekowacquah155
      @emmanuelekowacquah155 Год назад

      Okay, so I just read most of the permissions used are for android 10 and below.

  • @rahulchaurasia5011
    @rahulchaurasia5011 2 года назад +1

    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 ??

  • @KhinYadanarZaw-ll6cq
    @KhinYadanarZaw-ll6cq Год назад

    Dexter is useful to manage multiple permissions , which is better ?

  • @redballtoy
    @redballtoy Год назад +1

    this code will only work for API

  • @the_sharma_amit
    @the_sharma_amit 3 года назад

    thanks bro.. from india

  • @ohmegatech666
    @ohmegatech666 Год назад

    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

  • @timothyzhukov1159
    @timothyzhukov1159 2 года назад +1

    Awesome! 👍

  • @matt-g-recovers
    @matt-g-recovers 3 года назад

    Very cool Philipp!

  • @dharmeshbasapati4497
    @dharmeshbasapati4497 2 года назад

    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,

  • @hxrin3748
    @hxrin3748 4 года назад +3

    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

  • @betaaccount7450
    @betaaccount7450 3 года назад +2

    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

    • @51bpegasi
      @51bpegasi 3 года назад

      having the same problem here, unfortunately

    • @betaaccount7450
      @betaaccount7450 3 года назад +1

      @@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

    • @51bpegasi
      @51bpegasi 3 года назад

      @@betaaccount7450 you are right! thanks!
      also tried A C's suggestion, it works too: if(!hasLocationBackgroundPermission() && hasLocationForegroundPermission())

  • @mehmetdurmaz636
    @mehmetdurmaz636 2 года назад

    You are King.

  • @prolaymm
    @prolaymm Год назад

    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.

  • @theai2020
    @theai2020 3 года назад

    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?

  • @footballCartoon91
    @footballCartoon91 2 года назад

    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?

  • @PJ-od9ev
    @PJ-od9ev 2 года назад

    You are amazing thanks a lot

  • @parthibanakt7090
    @parthibanakt7090 2 года назад

    How to analyze in Androidmanifest.xml file mentioned permissions are required for the application? It means how to find unwanted permissions ?

  • @sergiaguilar1
    @sergiaguilar1 3 года назад +2

    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.

  • @manishpingale6558
    @manishpingale6558 4 года назад +1

    Why there is '=" sign in front of that function? Thanks for AWESOME content

    • @hxrin3748
      @hxrin3748 4 года назад +4

      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

    • @manishpingale6558
      @manishpingale6558 4 года назад

      @@hxrin3748 oh oh thanks got it 👍

  • @lara-kp7lp
    @lara-kp7lp 2 года назад

    Whenever i create app with internet permission it only works when installed from android studio.Not as apk why so?

  • @jishnunkrishnan5783
    @jishnunkrishnan5783 3 года назад

    Thank You

  • @GeorgeTrialonis
    @GeorgeTrialonis 2 года назад +1

    No Permission prompt after I press the button. Can somebody help?

    • @rowenarrow
      @rowenarrow 2 года назад +1

      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.

    • @devprasad8767
      @devprasad8767 2 года назад

      @@rowenarrow did you figure out?

    • @broma3974
      @broma3974 Год назад +2

      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.

  • @gurarshdeepsingh5881
    @gurarshdeepsingh5881 4 года назад

    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 ??

  • @MCA_HimanshuSeth
    @MCA_HimanshuSeth 4 года назад

    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
      @PhilippLackner  4 года назад

      Background location is only for API 29 (android Q)
      I don't get your second question

    • @MCA_HimanshuSeth
      @MCA_HimanshuSeth 4 года назад

      @@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

    • @krzysztoffarys7189
      @krzysztoffarys7189 3 года назад +1

      @@MCA_HimanshuSeth i can be your mentor

    • @arturrejment4016
      @arturrejment4016 3 года назад +1

      @@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!

    • @MCA_HimanshuSeth
      @MCA_HimanshuSeth 3 года назад

      @@krzysztoffarys7189 how can I contact you ?

  • @billmolloy2264
    @billmolloy2264 Год назад

  • @iamfunny2155
    @iamfunny2155 3 года назад

    Pls how to open permission for data collector of code on Android studio

  • @rupendrakumar3061
    @rupendrakumar3061 3 года назад

    How to enable location services in WebView...?

  • @denisk3852
    @denisk3852 3 года назад

    Do notifications need permissions?

  • @footballCartoon91
    @footballCartoon91 2 года назад

    @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?

    • @mayor3367
      @mayor3367 Год назад

      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.

  • @kartikeyarawat1754
    @kartikeyarawat1754 3 года назад

    You're OG!

  • @Hamza-Shreef
    @Hamza-Shreef Год назад

    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
    }

  • @atharvaaswale7316
    @atharvaaswale7316 3 года назад +1

    What about internet permission?

    • @MrDari88
      @MrDari88 3 года назад +1

      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).

  • @Hyfh2
    @Hyfh2 3 года назад

    why not able to android R this permission?

  • @jacobakoto9841
    @jacobakoto9841 3 года назад

    Will this code work for android 11?

  • @Carisma2012
    @Carisma2012 Год назад +1

    my brain:Lord's mercy

  • @gutic4824
    @gutic4824 4 года назад

    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

  • @re_allyedge
    @re_allyedge 4 года назад +1

    I knew it, you are german. Me too :D

  • @basba_qal
    @basba_qal 8 месяцев назад

    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.

  • @briacroa6681
    @briacroa6681 3 года назад +1

    too complex. start with one permission.

  • @gilsonjuniorpro
    @gilsonjuniorpro 2 года назад

    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

  • @rishabjain2634
    @rishabjain2634 2 года назад

    can some one help me out after the activtyCompat(....)==packageManager.PERMISSION_GRANTED for me the PERMISSION_GRANTED IS NOT SHOWING??

    • @broma3974
      @broma3974 Год назад

      "PackageManager" not "packageManager". That's probably your mistake as well as anyone else who has the same problem.

  • @LenaleiChanTing
    @LenaleiChanTing 6 месяцев назад

    my button part at the end isnt working