Android Runtime Permissions in API-23 + Using PermissionUtil

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

PermissionUtil 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" />


Got any Android Question?