Skip to content

Commit

Permalink
Update file utils
Browse files Browse the repository at this point in the history
Add methods to get file from URI.
  • Loading branch information
pranavpandey committed Jan 26, 2024
1 parent 3579caa commit 9ef1510
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,42 @@ public static void unzip(@NonNull File zip, @NonNull File extractTo)
}
}

/**
* Returns file from the URI.
*
* @param uri The URI to get the file.
*
* @return The file from the URI.
*
* @see Uri#getPath()
*/
public static @Nullable File getFileFromUri(@Nullable Uri uri) {
if (uri == null || uri.getPath() == null) {
return null;
}

return new File(uri.getPath());
}

/**
* Returns file from the URI string.
*
* @param uri The URI to get the file.
*
* @return The file from the URI string.
*
* @see Context#getContentResolver()
*/
public static @Nullable File getFileFromUri(@Nullable String uri) {
try {
return getFileFromUri(Uri.parse(uri));
} catch (Exception e) {
e.printStackTrace();

return null;
}
}

/**
* Returns file name from the URI.
*
Expand Down

0 comments on commit 9ef1510

Please sign in to comment.