permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.21k stars 1.44k forks source link

Did you really checked that dispatcher can work on Fragment in Java-AS project #700

Closed owensuen closed 3 years ago

owensuen commented 3 years ago

I'm using dispather 4.8.0 on Fragment in Java-AS project, but it cannot work when firs time got the permission from user but in Activity it work fine

@RuntimePermissions public class CameraFragment extends Fragment implements ActivityCompat.OnRequestPermissionsResultCallback {

@Override public void onViewCreated(@NonNull final View view, Bundle savedInstanceState) { Activity activity = getActivity(); if (activity == null) { return; } ButterKnife.bind(this, view); CameraFragmentPermissionsDispatcher.logWithPermissionCheck(this, "FUCK FUCK"); }

@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
public void log(String string){
    ULog.w(TAG, "log: ----------------////////////////////////////// " + string);
}

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

}

build

implementation "com.github.hotchemi:permissionsdispatcher:4.8.0"
annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:4.8.0"
owensuen commented 3 years ago

I found it. ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,@NonNull int[] grantResults) is not suitable for PrmissionDispatcher. instead, we should use the original function #onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) which belongs to Fragment itself. sorry for bothering you guys