Android M - anyway to know if a user has chosen never to show the grant permissions dialog ever again?

邮差的信 提交于 2019-12-12 03:24:21

问题


If an all calls ActivityCompat.requestPermissions() then the OS displays a dialog with Deny or Permit buttons. There is also a never show this again tick box.

However there's no way that I can see for the app to know if the user has ticked this box - within onRequestPermissionsResult() the grantResults parameter is PERMISSION_DENIED if the user clicks Deny and also if the user ticks the tick box before clicking Deny. So is there anyway an app can find out if the user doesn't want to see that dialog again?


回答1:


You can use ActivityCompat.shouldShowRequestPermissionRationale() - it will return false in a few cases:

  • You've never asked for the permission before
  • The user has checked the 'never again' checkbox
  • The permission has been disabled by policy (say, in a work situation)

By combining this with a shared preference to store if you've ever asked for permission, you can effectively determine if they'll actually see the dialog when you call requestPermissions().



来源:https://stackoverflow.com/questions/33224432/android-m-anyway-to-know-if-a-user-has-chosen-never-to-show-the-grant-permissi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!