Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle permissions change while in app

I am having a hard time understanding the right way to handle a user changing a permission while my app is still running in the background.

In my app I have a location class that registers for location changes and when the location changes the status is sent to a server. However this runs in the background.

When my app is launched I check with the user if its ok to use location services and if so I proceed with setting up that class. However the user can background my app and go into settings and remove that permission. I can, and will certainly check that the permission is enabled in my location class before asking for a location from the location service to avoid a crash. However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.

EDIT:

It does seem that android restarts your app if a permission has been revoked in settings. However I have confirmed that as of now android does NOT restart your app if a permission was granted though settings.

like image 866
lostintranslation Avatar asked Dec 14 '15 14:12

lostintranslation


People also ask

Why do apps use permissions in the background?

Android app permissions can give apps control of your phone and access to your camera, microphone, private messages, conversations, photos, and more. App permission requests pop up the first time an app needs access to sensitive hardware or data on your phone or tablet and are usually privacy-related.

What does allow only while using the app mean?

Here's what's happening in your neck of the woods. Allow While Using App — This gives the app permission to access your precise location, but only when the app is open.


2 Answers

However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.

Raise a Notification, alerting the user that your app cannot do its intended work without the permission that they revoked. Have the Notification tie into an Activity via a PendingIntent where the user will be able to grant that permission.

like image 81
CommonsWare Avatar answered Nov 15 '22 16:11

CommonsWare


I read somewhere that your app gets killed when the user changes the permissions on Android-M so you can be sure that this won't change while your app is running. It will been killed when this changes.

As reference check this video: https://www.youtube.com/watch?v=f17qe9vZ8RM

like image 45
rekire Avatar answered Nov 15 '22 15:11

rekire