protected boolean ensurePermission(final String[] permissions){
  mPermissionList=new ArrayList<>();
  if (permissions.length > 0) {
    for (int i=0; i < permissions.length; i++) {
      if (ContextCompat.checkSelfPermission(getContext(),permissions[i]) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),permissions[i])) {
          if (permissions[i] == Manifest.permission.ACCESS_COARSE_LOCATION) {
            final PermissionRationaleDialogFragment dialog=PermissionRationaleDialogFragment.getInstance(getString(R.string.rationale_message_location));
            dialog.show(getChildFragmentManager(),null);
            return false;
          }
        }
 else {
          mPermissionList.add(permissions[i]);
        }
      }
 else {
        onPermissionGranted(permissions[i]);
      }
    }
    if (mPermissionList.size() > 0) {
      onRequestPermission();
      return true;
    }
  }
  return true;
}

protected boolean ensurePermission ( final String [ ] permissions ) { mPermissionList = new ArrayList < > ( ) ; if ( permissions . length > 0 ) { for ( int i = 0 ; i < permissions . length ; i ++ ) { if ( ContextCompat . checkSelfPermission ( getContext ( ) , permissions [ i ] ) != PackageManager . PERMISSION_GRANTED ) { if ( ActivityCompat . shouldShowRequestPermissionRationale ( getActivity ( ) , permissions [ i ] ) ) { if ( permissions [ i ] == Manifest . permission . ACCESS_COARSE_LOCATION ) { final PermissionRationaleDialogFragment dialog = PermissionRationaleDialogFragment . getInstance ( getString ( R . string . rationale_message_location ) ) ; dialog . show ( getChildFragmentManager ( ) , null ) ; return false ; } } else { mPermissionList . add ( permissions [ i ] ) ; } } else { onPermissionGranted ( permissions [ i ] ) ; } } if ( mPermissionList . size ( ) > 0 ) { onRequestPermission ( ) ; return true ; } } return true ; }
ensures the required permission has been granted by the user . on android pre - 6 . 0 it always returns true . in case the permission has not been granted this method may also show a dialog with rationale .
