2

I was wondering, how to know user check "Never ask again" before calling requestPermissions.

I had gone through Android M - check runtime permission - how to determine if the user checked "Never ask again"? but can't get a proper solution yet.

Before that, please allow me to explain my motive.

I have the following feedback dialog form.

enter image description here

When user tick on Reply to me explicitly, I will perform requestPermissions if permissions is not granted yet. There can be 3 possible outcome.

1st outcome. Happens when calling requestPermissions for 1st time

enter image description here

2nd outcome. Happens when calling requestPermissions for 2nd, or more time

enter image description here

3rd outcome. Happens when user has ticked "Never ask again"

No dialog will be shown. requestPermissions will never pop up any dialog. I need untick the checkbox on behalf of user, as onRequestPermissionsResult will tell me permission is denied.

3rd outcome will produce bad user experience. As when user tick on the checkbox, it will become untick immediately.

I would like to hide Reply to me before making feedback form visible. To do this, I need to know whether user has already check "Never ask again".

shouldShowRequestPermissionRationale doesn't help much. As, shouldShowRequestPermissionRationale will return false in 2 cases

  1. User has already check "Never ask again".
  2. requestPermissions is never called before.

I don't find a way to differentiate between both.

Community
  • 1
  • 1
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
  • There seems no easy way, but in your case perhaps you may seek the permission first before displaying your dialog. You may then determine whether to show the option depending on the result of the permission check. – headuck Jan 03 '16 at 05:44
  • I try to avoid asking permission before showing feedback dialog. As this might create unpleasant user experience. User will wonder why do I need to provide contacts information in order to show up feedback dialog form. – Cheok Yan Cheng Jan 03 '16 at 14:39
  • Still another way is to separate the "reply to me" question if you do not already have the permission in a separate dialog - in such case you can ask the question after the feedback dialog and the permission is granted. Might be less odd, but there may be a problem of too many successive dialogs... – headuck Jan 03 '16 at 15:19
  • Best solution found on this link: [https://stackoverflow.com/a/33514501/4156299](https://stackoverflow.com/a/33514501/4156299) – Abhi Oct 23 '20 at 13:16

1 Answers1

3

When you ask for permission, save a boolean shared preference as true. You'll then be able to check the value of that to know if you have already asked for permission and know if shouldShowRequestPermissionRationale() is returning false because you've never asked before or because they said never again or because the permission is disabled by device policy.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • 2
    But please note that the result of `shouldShowRequestPermissionRationale()` might be reset, if the user switches the permission outside of the app - https://code.google.com/p/android-developer-preview/issues/detail?id=3103 – headuck Jan 03 '16 at 05:54
  • 3
    I can have a flag in shared preference, to keep track whether "Never ask again" is ticked. However, will it have possible that it may out of sync with real system value? Mean, user may clear the "Never ask again" system flag outside the app. Yet, retain true value of the "Never ask again" flag, in shared preference? – Cheok Yan Cheng Jan 03 '16 at 15:21
  • 4
    This is so ridiculous, the developer must take care of something that the system itself imposes. – Leonardo Nov 29 '16 at 17:08
  • Check out this answer for a nice way to handle checking which scenario your in when requesting a permission: https://stackoverflow.com/a/52596674/753964 – bmjohns Oct 01 '18 at 18:54