Grato por sua visita. Neste momento esta página está apenas disponível em inglês.

SDK for Android Listing Nodes

Listing nodes using the SDK for Android

Getting Node Information

All metadata associated with files and folders are represented as nodes. If we want to retrieve the information for a single Node, we can use the getNode() method.

// Get node information for a single node.
GetNodeResponse response = client.getNode(new GetNodeRequest(nodeId));

It is often the case that we want to list multiple nodes at a time. This is accomplished with one of the listing methods.

  • listNodes - Get the list nodes that meet a filter criteria.
  • listChildren - Get the list nodes that are children of a parent; such as a folder.
  • listNodesInTrash - Get the list nodes that are in the trash.

List Nodes

// ListNodes is an example of a paged request. We may not get all of the nodes
// back in one request. In order to get all of the data, we must loop until we
// get all of the continuation tokens or a null in the response.
String nextToken = null;
do {
    ListNodesRequest listNodesRequest = new ListNodesRequest();
    listNodesRequest.setStartToken(nextToken);
    ListNodesResponse response = client.listNodes(listNodesRequest);
    nextToken = response.getNextToken();
    List<Node> nodes = response.getData();

    // ... Do something with the nodes ...
}
while (nextToken != null);

The continuation token returned from getNextToken() is valid for 10 minutes.

Listing a Folder

A folder’s contents can be listed using the listChildren() method.

// ListChildren is an example of a paged request. We may not get all of the
// nodes back in one request, so we must loop until we get all of the
// continuation tokens or a null in the response.
String nextToken = null;
do {
    // Make a synchronous (blocking) call to Amazon Drive that lists
    // all of the children for the node.
    ListChildrenRequest listChildrenRequest = new ListChildrenRequest(folderNodeId);
    listChildrenRequest.setStartToken(nextToken);
    ListChildrenResponse response = client.listChildren(listChildrenRequest);
    nextToken = response.getNextToken();
    List<Node> nodes = response.getData();

    // ... Do something with the nodes ...

}
while (nextToken != null);

The ListChildrenResponse object contains the children in the data field. If there are more results than the page size, then a continuation token is set in the response. Get this continuation token with the getNextToken() method and set the value for the next request.

The continuation token returned from getNextToken() is valid for 10 minutes.

Listing with Filters

Filters can be used with the listing requests to return the required subset of nodes. For more information about filtering nodes, see the filtering section of the RESTful Amazon Drive API.

Support

If you have any questions, see the Developer Forum.