Easypermissions 不 return 方法

Easypermissions does not return to Method

我正在使用 Easypermissions 库在运行时请求权限。

public class MyFragment extends Fragment {

private final int RC_FINE_LOCATION = 1;
private final String[] fineLocationPerms = {Manifest.permission.ACCESS_FINE_LOCATION};

private String searchTag = "";

private void checkLocationForPoiSearch( String tag) throws  SecurityException {
    if(hasLocationPermissions()) {
       .....
    } else {
        this.searchTag = tag ;
        EasyPermissions.requestPermissions(this, "test", RC_FINE_LOCATION, fineLocationPerms);
    }
}

@AfterPermissionGranted(RC_FINE_LOCATION)
protected void permissionsGranted() {
    Log.d(TAG, "permissions granted");
    checkLocationForPoiSearch(this.searchTag);
}

 private boolean hasLocationPermissions() {
    boolean hasPermissions = false ;

    if(EasyPermissions.hasPermissions(this.getContext(), fineLocationPerms)) {
        hasPermissions = true;
    }

    return hasPermissions;
}

}   

我的预期是,Easypermissions 会在用户授予相应权限后调用permissionsGranted 方法。但由于某些原因,方法 permissionsGranted 将不会被调用。那么知道我做错了什么吗?

此致

迈克尔

所以经过一些调试我得到了解决方案。您必须重写以下方法

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

    EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}