How Do We Distinguish Never-Asked From Stop-Asking in Android M's Runtime Permissions?

后端 未结 10 692
萌比男神i
萌比男神i 2020-11-28 20:48

When it comes to the M Developer Preview runtime permissions, according to Google:

  1. If you have never asked for a certain permission before, just ask for it<

10条回答
  •  孤街浪徒
    2020-11-28 21:14

    No, you don't need to track whether or not you asked for the permission, and you don't need to distinguish Never-Asked From Stop-Asking.

    The state 1 and 3 are the same for app developer: you need the permission and ActivityCompat.checkSelfPermission != PackageManager.PERMISSION_GRANTED, then you just ask for the permission via ActivityCompat.requestPermissions(), whenever user tapped the feature that requires the permission, no matter how many times you have requested. User will eventually "Grant" it, or "Deny" it with "never ask again" checked. The design does NOT discourage you from popup the permission request dialogbox multiple times.

    However, the design does encourage you to explain the purpose of the permission at some point - your state 2. shouldShowRequestPermissionRationale() is NOT used to determine if you should request for permission, it's used to determine if you should show explanations, BEFORE you request for permission.

    A couple more explanation regarding the state 3:

    1. Yes, we should stop bothering user by stop showing the explanation, not stop request. That's why they provided the shouldShowRequestPermissionRationale().
    2. It's not bothering to keep request for permission. After user chose "never ask again", ActivityCompat.requestPermissions() will not popup dialogbox anymore.
    3. It's better to disable the relevant UI every time we find out we don't have the permission, during single user session. Instead of disable the UI after shouldShowRequestPermissionRationale() return false.

提交回复
热议问题