ab11
ab11

Reputation: 20090

Using the Android Api, how to retrieve entire file path?

Given a com.box.androidlib.Utils.BoxUtils.BoxFolder object, I would like to recurse the object’s parent folders to retrieve the path from the root.

I would hope to do this with something like the below code, where currentBoxFolder is retrieved using Box.getAccountTree(…) as done in the Browse class of the included sample code. However, the getParentFolder returns null (for non-root folders for which I expect it to be non-null).

I figure that it might be possible to populate the parent variable by modfiying the source to fetch additional attributes, but I was able to. Any suggestions?

List<BoxFolder> parentDirs = new ArrayList<BoxFolder>();
parentDirs.add(new BoxFolderEntry(currentBoxFolder));

BoxFolder parent = currentBoxFolder.getParentFolder();
while(parent != null)
{
    parentDirs.add(0, parent);
    parent = parent.getParentFolder();
}

Upvotes: 0

Views: 296

Answers (1)

Rico Yao
Rico Yao

Reputation: 991

If the end goal is for you to know the path from the root to a folder, there are a couple ways to solve this:

OPTION 1:

Maintain your own map of folder_ids and folder_names as your application fetches them. Presumably, in order to get the id of currentBoxFolder, you would have had to do getAccountTree() calls on all its parents before-hand. So if that's the case, you could maintain 2 maps:

Folder ID => Parent Folder ID

Folder ID => Folder Name

From those two maps, you should always be able to get the path from the root.

OPTION 2:

There are 2 params that can be added to the Box.getAccountTree() method that will allow you to know the path:

"show_path_ids"

"show_path_names"

These params haven't been documented yet (we'll do that), but they will cause BoxFolder.getFolderPathIds() and BoxFolder.getFolderPath() to return values such as:

"/5435/4363"

"/blue folder/green folder"

Upvotes: 1

Related Questions