1

I want to avoid ask others permission if the user not grant one.

For example: I ask for read/write external storage and camera, if the user deny the first, the library ask for camera permission, camera permission is redundant in this case.

RxPermissions.getInstance(getActivity()).request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
                .subscribe(granted -> {
                    if (granted) {
                       dispatchCamera();
                    } else {
                        showError();
                    }
                });

I think I could use requestEach, but I dont know how stop to emit items if one permission is not granted and also I cant obtain the final result, if the user grant all permissions.

4

1 回答 1

3

I suppose your problem was solved, but I gonna place answer, for somebody else, who get into same trouble.

All you need is takeUntil or takeWhile operator with requestEach(depends what stream behaviour you want). TakeUntil unsubscribe you from stream, and bring you only events with granted permissions and one of permission denied inclusive.If you want get only permission granted events without any of them == denied, pls use takeWhile opertator. Just maybe you would have to experement with this code a while, cause I didnt use this library yet, and maybe something would behave not exactly as you want.

So code might be like this:

 RxPermissions
      .getInstance(getActivity())
      .requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE, 
         Manifest.permission.READ_EXTERNAL_STORAGE, 
         Manifest.permission.CAMERA)
      .takeWhile(permission -> permission.granted)
      //or use take untill if you want to get permission.granted == false event
      //.takeUntil(permission -> !permission.granted)
      .subscribe(granted -> {
        if (granted) {
           dispatchCamera();
        } else {
           showError();
        }
      });
于 2017-02-05T19:50:57.997 回答