/**
  * Creates a new instance of a dialog displaying the rationale for the use of the location
  * permission.
  *
  * <p>The permission is requested after clicking 'ok'.
  *
  * @param requestCode Id of the request that is used to request the permission. It is returned
  *     to the {@link ActivityCompat.OnRequestPermissionsResultCallback}.
  * @param finishActivity Whether the calling Activity should be finished if the dialog is
  *     cancelled.
  */
 public static RationaleDialog newInstance(int requestCode, boolean finishActivity) {
   Bundle arguments = new Bundle();
   arguments.putInt(ARGUMENT_PERMISSION_REQUEST_CODE, requestCode);
   arguments.putBoolean(ARGUMENT_FINISH_ACTIVITY, finishActivity);
   RationaleDialog dialog = new RationaleDialog();
   dialog.setArguments(arguments);
   return dialog;
 }
 /**
  * Requests the fine location permission. If a rationale with an additional explanation should be
  * shown to the user, displays a dialog that triggers the request.
  */
 public static void requestPermission(
     AppCompatActivity activity, int requestId, String permission, boolean finishActivity) {
   if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
     // Display a dialog with rationale.
     RationaleDialog.newInstance(requestId, finishActivity)
         .show(activity.getSupportFragmentManager(), "dialog");
   } else {
     // Location permission has not been granted yet, request it.
     ActivityCompat.requestPermissions(activity, new String[] {permission}, requestId);
   }
 }