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:
- The permission dialog will popup every time that operation is about to be performed to grant permission.
- 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
add a comment |
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:
- The permission dialog will popup every time that operation is about to be performed to grant permission.
- 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
add a comment |
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:
- The permission dialog will popup every time that operation is about to be performed to grant permission.
- 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
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:
- The permission dialog will popup every time that operation is about to be performed to grant permission.
- 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
android
edited Nov 11 at 21:06
OsipXD
718818
718818
asked Nov 11 at 16:35
Ab.Ab
64
64
add a comment |
add a comment |
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()
.
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
add a comment |
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.
add a comment |
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()
.
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
add a comment |
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()
.
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
add a comment |
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()
.
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()
.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 11 at 16:42
Gabe Sechan
66.5k96096
66.5k96096
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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