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:"
Shared publiclyView activity