Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Asking for Permission at Runtime


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 to display a rationale to the user


Since Locatr’s mission is on the obvious side, you will not implement a rationale in this exercise – at
least, not until the challenge at the end of this chapter.

Free download pdf