Skip to content

The easiest way to add support for run-time permission in a fragment.

License

Notifications You must be signed in to change notification settings

mptrista/PermissionHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

PermissionHelper

The easiest way to add support for run-time permission in a fragment.

1st step: Init a permission helper

private PermissionHelper permissionHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    permissionHelper = new PermissionHelper();
}

2nd step: Give the result onPermissionGranted to the PermissionHelper

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    permissionHelper.onRequestPermissionResult(this, requestCode, permissions[0], grantResults);
}

3nd step: Requesting a specific permission inside of a Fragment

permissionHelper.executeWithPermCheck(this, PermissionHelper.STORAGE,
            new PermissionHelper.Callback() {
                @Override
                public void onPermissionGranted() {
                    // When the permission is granted
                }

                @Override
                public void onRationaleNeeded() {
                    // The case when Don't show again is checked
                }
            });

The reference to the callback is Weak so if you want to be sure make a strong reference to it.

About

The easiest way to add support for run-time permission in a fragment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages