The OneDrive SDK for Android allows you to work with item collections in OneDrive.
Collection information is contained within a BaseCollectionPage
object, to which there are three core aspects:
getCurrentPage
The list of items within the current page.getNextPage
The next page request builder.null
if there are no additional pages.getRawObject
The json that represents this page response, containing additional data.
There are several navigation properties within the OneDrive service which can be expanded and returned in collections pages. In order to access these properties, the service request needs to call expand(...)
once the request is issued.
Name | Description |
---|---|
itemId | The item id of the item that has the children. |
propertyToExpand | The name of the navigation property to expand. |
callback | The callback when the get call is returned. |
final String itemId = "0000000000000000000000";
final String propertyToExpand = "children";
final ICallback<Item> callback = new ICallback<Item> {
@Override
public void success(final Item result) {
final IItemCollectionPage page = result.children;
Toast.makeText(getActivity(), "Got children", Toast.LENGTH_LONG).show();
}
...
// Handle failure
}
oneDriveClient
.getDrive()
.getItems(itemId)
.buildRequest()
.expand(propertyToExpand)
.get(callback);
You can reference navigation properties directly by using the getChildren()
function within the item's request builder.
Name | Description |
---|---|
itemId | The item id of the item that has the children. |
callback | The callback when the get call is returned. |
final String itemId = "0000000000000000000000";
final ICallback<IItemCollectionPage> callback = new ICallback<IItemCollectionPage> {
@Override
public void success(final IItemCollectionPage result) {
Toast.makeText(getActivity(), "Got children", Toast.LENGTH_LONG).show();
}
...
// Handle failure
}
oneDriveClient
.getDrive()
.getItems(itemId)
.getChildren()
.buildRequest()
.get(callback);
When getting a collection response, the getNextPage()
function will return the null if there are no more pages, or the request builder to get the next page. By using these request builders you can retrieve all of the items under a collection no matter the size.
Name | Description |
---|---|
itemId | The item id of the item that has the children |
callback | The callback when the get call is returned |
final String itemId = "0000000000000000000000";
final ICallback<IItemCollectionPage> callback = new ICallback<IItemCollectionPage> {
@Override
public void success(final IItemCollectionPage result) {
// If there was more pages retrieve them too
if (result.getNextPage() != null) {
result.getNextPage()
.buildRequest()
.get(new ICallback<IItemCollectionPage> ...);
}
Toast.makeText(getActivity(), "Got children", Toast.LENGTH_LONG).show();
}
...
// Handle failure
}
oneDriveClient
.getDrive()
.getItems(itemId)
.getChildren()
.buildRequest()
.get(callback);
You can create a folder within an item collection by using the request builders getDrive
, getItems
, and getChildren
with the create
method.
Name | Description |
---|---|
folderToCreate | The folder to create. |
parentId | The item id for the parent item. |
callback | The callback when the folder has been created. |
final String parentId = "0000000000000000000000";
final Item folderToCreate = new Item();
folderToCreate.name = "NewFolder";
folderToCreate.folder = new Folder();
final ICallback<Item> callback = new ICallback<Item> {
@Override
public void success(final Item result) {
Toast.makeText(getActivity(), "Created Folder", Toast.LENGTH_LONG).show();
}
...
// Handle failure
}
oneDriveClient
.getDrive()
.getItems(parentId)
.getChildren()
.buildRequest()
.create(folderToCreate, callback);