Shared publicly  - 
How to deal with permission denial on Android M
Pro-tip by +Wojtek Kaliciński

M Developer Preview 2 now includes a new method for Runtime Permissions: Activity.shouldShowRequestPermissionRationale().
It informs your app if it should display an explanation for the permission it is requesting before actually showing the permission dialog.

On a fresh app install, the method returns false, so you can ask for any required permissions straight away. If the user previously declined a permission, the method will return true. In that case you should consider displaying an explanation before invoking the permission dialog again. You should only do it if the permission is not self-explanatory.

Finally, if the app has no chance of having the permission granted, calls to shouldShowRequestPermissionRationale() will return false. This can happen for several reasons, such as the user selecting ""do not show again"" in the permission dialog. A false result means it doesn’t make sense to show any additional prompts with explanations.

Please note that, due to a bug, Fragment.shouldShowRequestPermissionRationale() always returns false on the M Developer Preview 2. This will be fixed in a future release. You can use getActivity().shouldShowRequestPermissionRationale() from Fragments in the meantime.

Check out our sample showing Runtime Permissions in action:"
Liran Barsisa's profile photoShintaro Katafuchi's profile photoFrançois-Xavier OXEDA's profile photoAkshay Thapa's profile photo
What about adding an intent so that users can be directed directly to the app's permission settings? If they selected "do not show again" and thus the method returns false, this would be nice to have if the user clicks on some functionality that cannot work without her re-granting the permission (say some dialog fragment saying that the disabled camera can only be re-enabled when the user grants this permission? Does she want to do so? and then a link to the permission setting for this app).

Right now it's only possible to guide them to the app's settings - and thus the user would have to follow another "link".

I know that this won't help for company policies denying permissions right away.
How can we differentiate between the following two cases?
Case 1: The app doesn't have a permission and the user has not been asked for the permission before. In this case, shouldShowRequestPermissionRationale() will return false because this is the first time we're asking the user.
Case 2: The user has denied the permission and selected "Don't ask again", in this case too shouldShowRequestPermissionRationale() will return false. 

I would want to send the user to the App's settings page in Case 2. How do i go about differentiating these two cases?
+François-Xavier OXEDA I got around the situation by storing whether the user has been asked for a particular permission before in SharedPrefs.
Using the data from the SharedPrefs and the return value of company-profile-fixes(), I'm able to differentiate b/w the two cases.
In case 1, the value in the SharedPrefs would be false, whereas in the 2nd case, since we have already ask for that permission, the value would be true.
Add a comment...