public class DocumentNode
- Object
- DocumentNode
One entry in the tree an app publishes through DocumentProvider: a folder or a file, as the
system file browser will show it.
A node is identified by an id that is stable for the lifetime of the item. The platform
remembers ids – a favourite in the Files app, a recent document, a running download – so
reusing an id for different content, or renumbering ids on every publish, makes the browser
point at the wrong thing. Derive the id from your own record key rather than from list order.
A file node names its content in one of two ways, matching the two modes described on
DocumentProvider:
setPath– a path relative toDocumentProvider.getSharedDirectory(), for bytes the app has already written into the shared container.setRemoteId– an opaque key the app’s HTTPS endpoint understands, for content fetched on demand.
A node with neither is a placeholder: it is listed, and opening it fails. A node with both prefers the local path, which is what makes a cached copy of a remote document open instantly.
DocumentNode root = DocumentNode.folder("root", "Invoices");
root.add(DocumentNode.file("inv-2031", "January.pdf")
.setContentType("application/pdf")
.setPath("invoices/january.pdf")
.setSize(len));
Constructors
public DocumentNode(String id, String name, boolean folder) | Creates a node. |
Methods
Inherited methods
Constructor details
DocumentNode
public DocumentNode(String id, String name, boolean folder)Parameters
idString- the stable identity of this item; must not be null or empty
nameString- the display name shown in the file browser
folderboolean- true for a folder, false for a file
Method details
folder
public static DocumentNode folder(String id, String name)Parameters
idString- the stable identity of this folder
nameString- the display name
Returns
file
public static DocumentNode file(String id, String name)Parameters
idString- the stable identity of this file
nameString- the display name, normally including an extension
Returns
getId
public String getId()isFolder
public boolean isFolder()getName
public String getName()setName
public DocumentNode setName(String name)Parameters
nameString- the display name
Returns
getContentType
public String getContentType()setContentType
public DocumentNode setContentType(String contentType)Parameters
contentTypeString- a MIME type such as
application/pdf
Returns
getPath
public String getPath()setPath
public DocumentNode setPath(String path)DocumentProvider.getSharedDirectory().Parameters
pathString- a relative path such as
invoices/january.pdf; a leading separator is ignored
Returns
getRemoteId
public String getRemoteId()setRemoteId
public DocumentNode setRemoteId(String remoteId)DocumentProvider.setRemoteEndpoint.Parameters
remoteIdString- an opaque key the endpoint understands
Returns
getSize
public long getSize()setSize
public DocumentNode setSize(long size)Sets the size in bytes. The browser shows this before any content is fetched, so it is worth setting for remote items even though it costs a round trip to learn.
For a remote item the size is NOT how the browser learns that content changed: content
can change to different bytes of the same length – a corrected total, a redacted page –
and the size would not move. setLastModified is the signal. Declare it and keep it
accurate across republishes; a remote item that declares no date is versioned by the
publication instead, which means it is re-fetched whenever anything is published, and one
that declares a date it never updates is served from the cache for good.
Items backed by the shared directory need none of this; their bytes are measured directly.
Parameters
sizelong- the size in bytes, or -1 when unknown
Returns
getLastModified
public long getLastModified()setLastModified
public DocumentNode setLastModified(long lastModified)Parameters
lastModifiedlong- milliseconds since the epoch, or -1 when unknown
Returns
add
public DocumentNode add(DocumentNode child)Parameters
childDocumentNode- the child node
Returns
getChildren
public List<DocumentNode> getChildren()