Check dangerous permissions every time











up vote
1
down vote

favorite













If your app needs a dangerous permission, you must check whether you have that permission every time you perform an operation that requires that permission.




https://developer.android.com/training/permissions/requesting

(in the case of API 23 and above)



Does it mean:




  1. The permission dialog will popup every time that operation is about to be performed to grant permission.

  2. Just to ContextCompat.checkSelfPermission() (programmatically) if permission is granted, if so then no permission dialog will popup.


or something else...



Why I need this answer:



I have a service that works in background multiple times a day(requesting location) NON-CONTINUOUSLY, lets say 3 times/day, does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work -or- it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ? (same question above reformed here).










share|improve this question




























    up vote
    1
    down vote

    favorite













    If your app needs a dangerous permission, you must check whether you have that permission every time you perform an operation that requires that permission.




    https://developer.android.com/training/permissions/requesting

    (in the case of API 23 and above)



    Does it mean:




    1. The permission dialog will popup every time that operation is about to be performed to grant permission.

    2. Just to ContextCompat.checkSelfPermission() (programmatically) if permission is granted, if so then no permission dialog will popup.


    or something else...



    Why I need this answer:



    I have a service that works in background multiple times a day(requesting location) NON-CONTINUOUSLY, lets say 3 times/day, does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work -or- it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ? (same question above reformed here).










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite












      If your app needs a dangerous permission, you must check whether you have that permission every time you perform an operation that requires that permission.




      https://developer.android.com/training/permissions/requesting

      (in the case of API 23 and above)



      Does it mean:




      1. The permission dialog will popup every time that operation is about to be performed to grant permission.

      2. Just to ContextCompat.checkSelfPermission() (programmatically) if permission is granted, if so then no permission dialog will popup.


      or something else...



      Why I need this answer:



      I have a service that works in background multiple times a day(requesting location) NON-CONTINUOUSLY, lets say 3 times/day, does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work -or- it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ? (same question above reformed here).










      share|improve this question
















      If your app needs a dangerous permission, you must check whether you have that permission every time you perform an operation that requires that permission.




      https://developer.android.com/training/permissions/requesting

      (in the case of API 23 and above)



      Does it mean:




      1. The permission dialog will popup every time that operation is about to be performed to grant permission.

      2. Just to ContextCompat.checkSelfPermission() (programmatically) if permission is granted, if so then no permission dialog will popup.


      or something else...



      Why I need this answer:



      I have a service that works in background multiple times a day(requesting location) NON-CONTINUOUSLY, lets say 3 times/day, does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work -or- it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ? (same question above reformed here).







      android






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 21:06









      OsipXD

      718818




      718818










      asked Nov 11 at 16:35









      Ab.Ab

      64




      64
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted











          does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work




          Probably not.




          it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ?




          Probably not.



          The quote from the documentation means that you need to call ContextCompat.checkSelfPermission() before you try performing an operation that needs a runtime permission (dangerous permissions). This does not display any UI. It merely lets you know whether or not you hold the permission.



          If you do not hold the permission, you will to request the permission from the user before you will be able to do whatever it is that you are trying to do. That needs to be performed from an activity or fragment, using requestPermissions().



          In your case, before you schedule the background work (WorkManager, JobScheduler, etc.), use requestPermissions(), and only schedule that work if the user grants you your desired permission(s).



          However, it is possible that the user will revoke the granted permissions. That is why your background work will need to call checkSelfPermission(). If that indicates that you do not hold the permission, you will need to raise a Notification that leads the user to your UI, where you can once again requestPermissions().






          share|improve this answer





















          • Nice detailed answer exactly what I wanted to here :) (my first question in stackoverflow , it says avoid commenting with "thanks" what do I say ? anyway, thank you for the answer @CommonsWare)
            – Ab.Ab
            Nov 11 at 17:03


















          up vote
          0
          down vote













          It means you need to call checkSelfPermission each time, and make sure the user didn't remove your permission (because if they did the action will fail, either with an error return or an exception). However if that returns false, the only way to get permission is to show the dialog. Or you can just not do whatever you were planning to.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250837%2fcheck-dangerous-permissions-every-time%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted











            does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work




            Probably not.




            it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ?




            Probably not.



            The quote from the documentation means that you need to call ContextCompat.checkSelfPermission() before you try performing an operation that needs a runtime permission (dangerous permissions). This does not display any UI. It merely lets you know whether or not you hold the permission.



            If you do not hold the permission, you will to request the permission from the user before you will be able to do whatever it is that you are trying to do. That needs to be performed from an activity or fragment, using requestPermissions().



            In your case, before you schedule the background work (WorkManager, JobScheduler, etc.), use requestPermissions(), and only schedule that work if the user grants you your desired permission(s).



            However, it is possible that the user will revoke the granted permissions. That is why your background work will need to call checkSelfPermission(). If that indicates that you do not hold the permission, you will need to raise a Notification that leads the user to your UI, where you can once again requestPermissions().






            share|improve this answer





















            • Nice detailed answer exactly what I wanted to here :) (my first question in stackoverflow , it says avoid commenting with "thanks" what do I say ? anyway, thank you for the answer @CommonsWare)
              – Ab.Ab
              Nov 11 at 17:03















            up vote
            2
            down vote



            accepted











            does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work




            Probably not.




            it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ?




            Probably not.



            The quote from the documentation means that you need to call ContextCompat.checkSelfPermission() before you try performing an operation that needs a runtime permission (dangerous permissions). This does not display any UI. It merely lets you know whether or not you hold the permission.



            If you do not hold the permission, you will to request the permission from the user before you will be able to do whatever it is that you are trying to do. That needs to be performed from an activity or fragment, using requestPermissions().



            In your case, before you schedule the background work (WorkManager, JobScheduler, etc.), use requestPermissions(), and only schedule that work if the user grants you your desired permission(s).



            However, it is possible that the user will revoke the granted permissions. That is why your background work will need to call checkSelfPermission(). If that indicates that you do not hold the permission, you will need to raise a Notification that leads the user to your UI, where you can once again requestPermissions().






            share|improve this answer





















            • Nice detailed answer exactly what I wanted to here :) (my first question in stackoverflow , it says avoid commenting with "thanks" what do I say ? anyway, thank you for the answer @CommonsWare)
              – Ab.Ab
              Nov 11 at 17:03













            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted







            does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work




            Probably not.




            it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ?




            Probably not.



            The quote from the documentation means that you need to call ContextCompat.checkSelfPermission() before you try performing an operation that needs a runtime permission (dangerous permissions). This does not display any UI. It merely lets you know whether or not you hold the permission.



            If you do not hold the permission, you will to request the permission from the user before you will be able to do whatever it is that you are trying to do. That needs to be performed from an activity or fragment, using requestPermissions().



            In your case, before you schedule the background work (WorkManager, JobScheduler, etc.), use requestPermissions(), and only schedule that work if the user grants you your desired permission(s).



            However, it is possible that the user will revoke the granted permissions. That is why your background work will need to call checkSelfPermission(). If that indicates that you do not hold the permission, you will need to raise a Notification that leads the user to your UI, where you can once again requestPermissions().






            share|improve this answer













            does this mean that runtime permission dialog has to show up 3 times a day whenever my service is going to perform its work




            Probably not.




            it has to show up only the first time my service starts and then it checks programmatically (only) the remaining 2 times if permission was granted ?




            Probably not.



            The quote from the documentation means that you need to call ContextCompat.checkSelfPermission() before you try performing an operation that needs a runtime permission (dangerous permissions). This does not display any UI. It merely lets you know whether or not you hold the permission.



            If you do not hold the permission, you will to request the permission from the user before you will be able to do whatever it is that you are trying to do. That needs to be performed from an activity or fragment, using requestPermissions().



            In your case, before you schedule the background work (WorkManager, JobScheduler, etc.), use requestPermissions(), and only schedule that work if the user grants you your desired permission(s).



            However, it is possible that the user will revoke the granted permissions. That is why your background work will need to call checkSelfPermission(). If that indicates that you do not hold the permission, you will need to raise a Notification that leads the user to your UI, where you can once again requestPermissions().







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 at 16:42









            CommonsWare

            759k13718481904




            759k13718481904












            • Nice detailed answer exactly what I wanted to here :) (my first question in stackoverflow , it says avoid commenting with "thanks" what do I say ? anyway, thank you for the answer @CommonsWare)
              – Ab.Ab
              Nov 11 at 17:03


















            • Nice detailed answer exactly what I wanted to here :) (my first question in stackoverflow , it says avoid commenting with "thanks" what do I say ? anyway, thank you for the answer @CommonsWare)
              – Ab.Ab
              Nov 11 at 17:03
















            Nice detailed answer exactly what I wanted to here :) (my first question in stackoverflow , it says avoid commenting with "thanks" what do I say ? anyway, thank you for the answer @CommonsWare)
            – Ab.Ab
            Nov 11 at 17:03




            Nice detailed answer exactly what I wanted to here :) (my first question in stackoverflow , it says avoid commenting with "thanks" what do I say ? anyway, thank you for the answer @CommonsWare)
            – Ab.Ab
            Nov 11 at 17:03












            up vote
            0
            down vote













            It means you need to call checkSelfPermission each time, and make sure the user didn't remove your permission (because if they did the action will fail, either with an error return or an exception). However if that returns false, the only way to get permission is to show the dialog. Or you can just not do whatever you were planning to.






            share|improve this answer

























              up vote
              0
              down vote













              It means you need to call checkSelfPermission each time, and make sure the user didn't remove your permission (because if they did the action will fail, either with an error return or an exception). However if that returns false, the only way to get permission is to show the dialog. Or you can just not do whatever you were planning to.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                It means you need to call checkSelfPermission each time, and make sure the user didn't remove your permission (because if they did the action will fail, either with an error return or an exception). However if that returns false, the only way to get permission is to show the dialog. Or you can just not do whatever you were planning to.






                share|improve this answer












                It means you need to call checkSelfPermission each time, and make sure the user didn't remove your permission (because if they did the action will fail, either with an error return or an exception). However if that returns false, the only way to get permission is to show the dialog. Or you can just not do whatever you were planning to.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 16:42









                Gabe Sechan

                66.5k96096




                66.5k96096






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250837%2fcheck-dangerous-permissions-every-time%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine