Methods Summary |
---|
public abstract boolean | canRead()Indicates whether the current context is allowed to read from this file.
|
public abstract boolean | canWrite()Indicates whether the current context is allowed to write to this file.
|
public abstract android.support.v4.provider.DocumentFile | createDirectory(java.lang.String displayName)Create a new directory as a direct child of this directory.
|
public abstract android.support.v4.provider.DocumentFile | createFile(java.lang.String mimeType, java.lang.String displayName)Create a new document as a direct child of this directory.
|
public abstract boolean | delete()Deletes this file.
Note that this method does not throw {@code IOException} on
failure. Callers must check the return value.
|
public abstract boolean | exists()Returns a boolean indicating whether this file can be found.
|
public android.support.v4.provider.DocumentFile | findFile(java.lang.String displayName)Search through {@link #listFiles()} for the first document matching the
given display name. Returns {@code null} when no matching document is
found.
for (DocumentFile doc : listFiles()) {
if (displayName.equals(doc.getName())) {
return doc;
}
}
return null;
|
public static android.support.v4.provider.DocumentFile | fromFile(java.io.File file)Create a {@link DocumentFile} representing the filesystem tree rooted at
the given {@link Uri}. This doesn't give you any additional access to the
underlying files beyond what your app already has.
{@link #getUri()} will return {@code file://} Uris for files explored
through this tree.
return new RawDocumentFile(null, file);
|
public static android.support.v4.provider.DocumentFile | fromSingleUri(android.content.Context context, android.net.Uri singleUri)Create a {@link DocumentFile} representing the single document at the
given {@link Uri}. This is only useful on devices running
{@link android.os.Build.VERSION_CODES#KITKAT} or later, and will return
{@code null} when called on earlier platform versions.
final int version = Build.VERSION.SDK_INT;
if (version >= 19) {
return new SingleDocumentFile(null, context, singleUri);
} else {
return null;
}
|
public static android.support.v4.provider.DocumentFile | fromTreeUri(android.content.Context context, android.net.Uri treeUri)Create a {@link DocumentFile} representing the document tree rooted at
the given {@link Uri}. This is only useful on devices running
{@link android.os.Build.VERSION_CODES#LOLLIPOP} or later, and will return
{@code null} when called on earlier platform versions.
final int version = Build.VERSION.SDK_INT;
if (version >= 21) {
return new TreeDocumentFile(null, context,
DocumentsContractApi21.prepareTreeUri(treeUri));
} else {
return null;
}
|
public abstract java.lang.String | getName()Return the display name of this document.
|
public android.support.v4.provider.DocumentFile | getParentFile()Return the parent file of this document. Only defined inside of the
user-selected tree; you can never escape above the top of the tree.
The underlying {@link android.provider.DocumentsProvider} only defines a
forward mapping from parent to child, so the reverse mapping of child to
parent offered here is purely a convenience method, and it may be
incorrect if the underlying tree structure changes.
return mParent;
|
public abstract java.lang.String | getType()Return the MIME type of this document.
|
public abstract android.net.Uri | getUri()Return a Uri for the underlying document represented by this file. This
can be used with other platform APIs to manipulate or share the
underlying content. You can use {@link #isDocumentUri(Context, Uri)} to
test if the returned Uri is backed by a
{@link android.provider.DocumentsProvider}.
|
public abstract boolean | isDirectory()Indicates if this file represents a directory.
|
public static boolean | isDocumentUri(android.content.Context context, android.net.Uri uri)Test if given Uri is backed by a
{@link android.provider.DocumentsProvider}.
final int version = Build.VERSION.SDK_INT;
if (version >= 19) {
return DocumentsContractApi19.isDocumentUri(context, uri);
} else {
return false;
}
|
public abstract boolean | isFile()Indicates if this file represents a file.
|
public abstract long | lastModified()Returns the time when this file was last modified, measured in
milliseconds since January 1st, 1970, midnight. Returns 0 if the file
does not exist, or if the modified time is unknown.
|
public abstract long | length()Returns the length of this file in bytes. Returns 0 if the file does not
exist, or if the length is unknown. The result for a directory is not
defined.
|
public abstract android.support.v4.provider.DocumentFile[] | listFiles()Returns an array of files contained in the directory represented by this
file.
|
public abstract boolean | renameTo(java.lang.String displayName)Renames this file to {@code displayName}.
Note that this method does not throw {@code IOException} on
failure. Callers must check the return value.
Some providers may need to create a new document to reflect the rename,
potentially with a different MIME type, so {@link #getUri()} and
{@link #getType()} may change to reflect the rename.
When renaming a directory, children previously enumerated through
{@link #listFiles()} may no longer be valid.
|