Asking for Permission at Runtime

Handling permissions at runtime requires you to do three things:

  • check to see whether you have permission before performing the operation

  • request permission if you do not already have it

  • listen for the response to your permissions request

Requesting permission means displaying the system-standard permissions request UI. If this dialog pops up in a place in your app where it is clear why you are asking your user for this permission, then this is all you need to do.

Sometimes, though, the reason is not obvious. Users often deny requests that do not make sense to them, so in those cases you will need to display a rationale. So those apps require a fourth step:

  • check to see whether you need ...

Get Android Programming: The Big Nerd Ranch Guide, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.