public class FileTools extends FileUtils
Each method is available statically, which means there is no need to instantiate FileTools. This is more memory efficient and allows for faster runtime then a class that has to be instantiated, first.
Please note that the Uri-objects used with methods introduced by this
class are always Uri-objects, and not URI-objects. This is important, as
there are also methods (inherited from FileUtils), which use URI-objects. These two classes are not interchangeable nor castable. They have nothing in common
but Java's general base class Object, and that both handle URIs. Both have a
completely different set of features and possibilities for use, and since this class is Android
specific, it introduces the Android class Uri to enhance the feature-set inherited
from FileUtils by this functionality.
| Constructor and Description |
|---|
FileTools() |
| Modifier and Type | Method and Description |
|---|---|
static String |
getApplicationCachePath(Context context)
Retrieves the application's cache directory as
String. |
static String |
getApplicationCachePath(Context context,
boolean external)
Retrieves the application's cache directory as
String. |
static File |
getFile(Context context,
Uri uri)
|
static String |
getPath(Context context,
Uri uri)
|
static Uri |
getUri(File file)
|
static boolean |
hasThumbnailSupport(Uri uri)
Returns true if the
Uri has thumbnail-support through MediaStore. |
static boolean |
isMediaUri(Uri uri)
Returns true if
Uri is a media URI. |
getExtension, getFile, getFile, getFile, getFileList, getPath, getPathWithoutFilename, getReadableFileSize, isLocalpublic static boolean isMediaUri(Uri uri)
Returns true if Uri is a media URI.
A media URI is either an audio, video or image MediaStore content URI. Every other
URI is not a media URI per definition of this method.
Please note that the Uri-object for this method is a Uri-object, and
not a URI-object.
uri - The Uri-object to checktrue if Uri-object is a media URI, false
otherwise.public static boolean hasThumbnailSupport(Uri uri)
Returns true if the Uri has thumbnail-support through MediaStore.
Please note that the Uri-object for this method is a Uri-object, and
not a URI-object.
uri - The Uri-object to checktrue if the file denoted by the Uri-object has
thumbnail-support through Android's Media-framework.public static Uri getUri(File file)
file - The File-object to convert.Uri-object.public static File getFile(Context context, Uri uri)
uri - The Uri-object to convert.File-object.public static String getPath(Context context, Uri uri)
Get a file path from a Uri as String.
In case the Uri denotes a content-URI, the appropriate ContentProvider
is queried to retrieve the path.
context - The Context-object in case the Uri is a content-URI.uri - The Uri-object to extract the file-path from.Uri-object.InvalidValueException - Thrown if the Uri object does not contain a valid file-path or the
ContentProvider query fails.public static String getApplicationCachePath(Context context, boolean external)
Retrieves the application's cache directory as String.
Upon the first call, this method queries for both cache-directories, the one on the internal storage and a possible one on an possible external storage. Both (if there is an external one) are then cached in a static variable which is simply returned on subsequent calls. If the external storage is not available for whatever reasons, but becomes available at a later time, the external storage will not be queried again and will remain inaccessible.
The directory returned is determined by the second parameter.
context - The Context-object used to identify and retrieve the cache-directory.external - Whether to return the directory on the external or internal storage.external is
true and the external storage is not available.public static String getApplicationCachePath(Context context)
Retrieves the application's cache directory as String.
This method is a convenience method to retrieve any cache-directory, with preference to the external storage, if available and mounted. If the external storage is not available, the internal storage will be used. The external storage will not be queried again for availability, in that case.
context - The Context-object used to identify and retrieve the cache-directory.