Karumi/Dexter

"Denied Listener" in Multiple permissions listener

saadbzu opened this issue · 1 comments

I used Multiple Permissions, how i detect the when user "deny"(Not permanently denied only denied) one or all permissions?

Hi @saadbzu the sample project contains an example of how you can know what permissions have been denied or permanently denied:

package com.karumi.dexter.sample;

import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionDeniedResponse;
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import java.util.List;

public class SampleMultiplePermissionListener implements MultiplePermissionsListener {

  private final SampleActivity activity;

  public SampleMultiplePermissionListener(SampleActivity activity) {
    this.activity = activity;
  }

  @Override public void onPermissionsChecked(MultiplePermissionsReport report) {
    for (PermissionGrantedResponse response : report.getGrantedPermissionResponses()) {
      activity.showPermissionGranted(response.getPermissionName());
    }

    for (PermissionDeniedResponse response : report.getDeniedPermissionResponses()) {
      activity.showPermissionDenied(response.getPermissionName(), response.isPermanentlyDenied());
    }
  }

  @Override public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions,
      PermissionToken token) {
    activity.showPermissionRationale(token);
  }
}

If you run the sample app you can find in this repository and press the REQUEST ALL button you'll be able to know which permissions are granted, which permissions are denied and which permissions are permanently denied:

Screenshot 2019-11-08 at 13 00 13

I'm closing this issues because I think my answer is the one you were looking for 😃