Such a new and awesome security functionality is RUN-TIME Permission
I am trying to understand it and make one demo for that But one question raise in my mind that when i am at handle user permission with DIALOG.
How to handle "Never ask Again"
Suppose my application MUST need Location/contact but user DENY it with "NEVER ASK AGAIN".
What can i do for that. Not all User understand my field is required.
ANY SUGGESTION?
open your app setting when user chose "Nerver ask again"
my example to handle RuntimePermission:
https://github.com/henrychuangtw/RuntimePermission
Use Dexter library
or
Use PermissionsDispatcher:
Step 1 : use PermissionsDispatcher library by hotchemi (the library is annotation based, simple to use and well documented)
Step 2 : you have to provide 4 annotated methods and one of them is @OnNeverAskAgain(Manifest.permission.[permission_you_want]) as below
Here is sample
First you need to implement
OnRequestPermissionsResultCallback
Listener
ofActivityCompat
class in yourActivity
and overridevoid onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
Method to check whether User is allowing or denying the permissionYou can do like this. Here i check for permission access for
WRITE_EXTERNAL_STORAGE
:Here is
onRequestPermissionsResult()
method will be called when user allow or deny Permission from Runtime permission dialog.You can also handle situation when User has checked never show Runtime Permission dialog for that you can show Snackbar or button to redirect user to your application settings page as you can not show permission dialog after user has checked
"Never ask again"
.Here i have used
Snackbar
to show relevant message to user about Permission andmainLayout
is id ofActivity's Main Layout
.Hope it helps you.
I have created a
library
that handle all thepermissions
for you. you can find it in here:PermissionHelper
To answer your question:
in order for you to know if the user
checked
never show again you'll have to check against two things, if the permission isdeclined
and noexplanation needed
if these two returned**true**
that means that the permission is no longer available to be asked again and the only solution to handle this case is to open the settings screen.P.S: the library i created handle all these kind of scenarios for you and returns callbacks for you to decide what to do next!. the library has two implementations