0

I´m updating an app to Marshmallow so I need to contemplate that the user could revocate permissions at runtime.

I know that when the user open the app, if some permissions are not enabled, then it will appear a dialog asking for those permissions. Whether which option is selected, the onRequestPermissionsResult will be called.

However, which method is called when the user disabled permissions from settings? I have a service running in the app, so if one of the permissions is disabled I should stop the service. Is there a way to do this, without entering in the app?

If more information is needed, just tell me!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Santiago Salem
  • 577
  • 2
  • 12
  • you can not https://stackoverflow.com/questions/31535088/android-m-programmatically-revoke-permissions – MJM Jan 11 '18 at 15:47
  • @jignesh Maybe I didn´t express well. When I said from settings, I refer to androids settings app. So a user could search there my app and revoke permissions. So if for example, location permission is revoked, then I shoud stop the service that sends gps data to a database. – Santiago Salem Jan 11 '18 at 15:53
  • "So if for example, location permission is revoked, then I shoud stop the service that sends gps data to a database" -- that happens automatically, as Android terminates your process. – CommonsWare Jan 11 '18 at 16:02
  • @CommonsWare Yes, the app is terminated and started again in a new process. In this new process the service continues running. Maybe I have a bad implementation of it, but I thought that the service would be stop also. – Santiago Salem Jan 11 '18 at 16:10
  • 1
    "In this new process the service continues running" -- no, it starts running, if you are using `START_STICKY` or `START_REDELIVER_INTENT`. If you are using `START_NOT_STICKY`, I would not expect the service to be started in the new process. The old service vanished when its process did. So long as your service validates that it holds the permission before it tries using what that permission protects, you are fine. If you no longer have the permission, raise a `Notification` to point out that you can no longer do your work. – CommonsWare Jan 11 '18 at 16:12
  • @CommonsWare I used `START_NOT_STICKY`, and the service didn´t start in the new process. Just one more question. If I revoke the permission, then my app gets killed (and also the service). So is there a way to raise a notification telling the user what happened? When the app is started again it will show a dialog asking for the permissions, but I wanna know if there is a way the user could acknowledge without openning the app. – Santiago Salem Jan 11 '18 at 18:09
  • 1
    @SantiagoSalem: "So is there a way to raise a notification telling the user what happened?" -- not until your app gets control again for some reason. – CommonsWare Jan 11 '18 at 18:10
  • Great! Thanks for your help! – Santiago Salem Jan 11 '18 at 18:10

1 Answers1

1

When user disable permission setting the application is restarted from the system

mguest
  • 121
  • 2
  • Yes, the app is killed and the app is started again, but the service continue running in the new process. – Santiago Salem Jan 11 '18 at 16:07
  • The service by default run in the same process of the Application, so also service should be restarted unless you specify the service to run in a separate process – mguest Jan 12 '18 at 10:15