Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 6.0 Permissions - Where to place permission requests?

with Androids new permission system, I was wondering how to implement it right. The tutorials about how and when to use the permissions seem to be pretty clear. However, I don't know who requests the permissions and where to request them.

So, basically my question is: should the Activity, who starts another Activity request the permission beforehand or should the Activity which requires the permission place the request?

If the Activity which requires the permission should request for it, should I call requestForPermission inside onCreate or in onStart?

Though it seems to be very simple questions, I haven't found any hints in the documentation.

Thanks.

like image 889
Denis Loh Avatar asked Dec 11 '15 16:12

Denis Loh


2 Answers

should the Activity, who starts another Activity request the permission beforehand or should the Activity which requires the permission place the request?

That is up to you. The main guidance is that there should be a clear tie from something the user does to your request for permissions:

  • If your app needs certain permissions to do anything meaningful, ask for them when your app starts up, perhaps after any sort of "welcome" presentation to advise them about why you need the permissions.

  • If your app needs certain permissions to do something based on the user performing some in-app action, like tapping on an action bar item or ListView row, ask for the permission when the user performs that action.

Asking for permissions at semi-random points in the app will simply lead to user confusion ("what did I do? why is it asking me this? and why are these questions appearing in an Stack Overflow answer?!?").

like image 151
CommonsWare Avatar answered Nov 15 '22 11:11

CommonsWare


If your app can't function properly without a particular permission might be good to have a welcome permission flow where you explain why need the permissions and ask for the grants. For example : Google maps and location permission

If some specific parts of the app need a separate permission you can call the permission check just before doing a method call that needs permission. In this case you can create a wrapper for your function that needs contact permission and always call that wrapper instead of the actual method. For example : Google maps and microphone permission when you try to use the search with voice functionality

More details http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

also check out https://github.com/permissions-dispatcher/PermissionsDispatcher could reduce a lot of permission code.

like image 42
g90 Avatar answered Nov 15 '22 11:11

g90