Using PermissionUtil
suggest changePermissionUtil is a simple and convenient way of asking for permissions in context. You can easily provide what should happen in case of all requested permissions granted (onAllGranted()
), any request was denied (onAnyDenied()
) or in case that a rational is needed (onRational()
).
Anywhere in your AppCompatActivity or Fragment that you want to ask for user’s permisssion
mRequestObject = PermissionUtil.with(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE).onAllGranted(
new Func() {
@Override protected void call() {
//Happy Path
}
}).onAnyDenied(
new Func() {
@Override protected void call() {
//Sad Path
}
}).ask(REQUEST_CODE_STORAGE);
And add this to onRequestPermissionsResult
if(mRequestObject!=null){
mRequestObject.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
Add the requested permission to your AndroidManifest.xml as well
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents