SDK for Android Listing Nodes

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.GetNodeResponseresponse=client.getNode(newGetNodeRequest(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.StringnextToken=null;do{ListNodesRequestlistNodesRequest=newListNodesRequest();listNodesRequest.setStartToken(nextToken);ListNodesResponseresponse=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.StringnextToken=null;do{// Make a synchronous (blocking) call to Amazon Drive that lists// all of the children for the node.ListChildrenRequestlistChildrenRequest=newListChildrenRequest(folderNodeId);listChildrenRequest.setStartToken(nextToken);ListChildrenResponseresponse=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.