Search code examples
androidandroid-permissionsandroid-6.0-marshmallow

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.


Solution

  • 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.