Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
94 lines (76 loc) · 3.2 KB

File metadata and controls

94 lines (76 loc) · 3.2 KB
Copy raw file
Download raw file
Outline
Edit and raw actions

Collections

Collections contain information about the items contained inside of them, including files and folders. The only collection available currently is a “Favorites” collection. The contents of the collection are discovered in a similar way in which the contents of a folder are discovered.

Get Collections

Existing collections can be retrieved by calling the getAllCollections(BoxAPIConnection) method. Currently only "Favorites" collection is supported.

Iterable<BoxCollection.Info> collections = BoxCollection.getAllCollections(api);
for (BoxCollection.Info collectionInfo : collections) {
	// Do something with the collection.
}

Get a Collection's Items

Every BoxCollection implements Iterable<BoxItem> which allows you to iterate over the collection's contents. The iterator automatically handles paging and will make additional network calls to load more data from Box when necessary.

BoxFolder folder = new BoxFolder(api, "id");
for (BoxItem.Info itemInfo : folder) {
    if (itemInfo instanceof BoxFile.Info) {
        BoxFile.Info fileInfo = (BoxFile.Info) itemInfo;
        // Do something with the file.
    } else if (itemInfo instanceof BoxFolder.Info) {
        BoxFolder.Info folderInfo = (BoxFolder.Info) itemInfo;
        // Do something with the folder.
    }
}

Add Items to a Collection

Add an item to a collection by calling setCollections(String...) on any BoxItem. Note that this method will overwrite all collections that the item belongs to.

BoxCollection favorites = null;
for (BoxCollection.Info info : BoxCollection.getAllCollections(api)) {
    if (info.getCollectionType().equals("favorites")) {
        favorites = info.getResource();
        break;
    }
}
BoxFile file = new BoxFile(api, "id");
file.setCollections(favorites);

Remove Items from a Collection

Remove an item from a collection by calling setCollections(String...) on any BoxItem and exclude the collection to wish to remove it from.

BoxFile file = new BoxFile(api, "id");
BoxFile.Info info = file.getInfo("collections");

ArrayList<BoxCollection> collections = new ArrayList<BoxCollection>();
for (BoxCollection.Info info : info.getCollections(api)) {
    // Include every existing collection except for favorites to remove the file
    // from the favorites collection.
    if (!info.getCollectionType().equals("favorites")) {
        collections.add(info.getResource());
    }
}
file.setCollections(collections.toArray());
Morty Proxy This is a proxified and sanitized view of the page, visit original site.