我拼命试图了解如何使用Android版OneDrive SDK。
这些示例应用仅描述了选择,保存或浏览。
我已经在这里实现了资源管理器:
https://github.com/OneDrive/onedrive-explorer-android

最后,我有这种代码:

final IOneDriveService oneDriveService = oneDriveHelper.getOneDriveService();
final Callback<Item> itemCallback = getItemCallback(app);
oneDriveService.getItemId(mItemId, mQueryOptions, itemCallback);


哪里

mItemId="root";


我试图通过这样做来更改mQueryOptions

mQueryOptions.put("q", "myKeyWord");


没有成功(只是列出根目录)

我尝试将mItemId替换为:

"root:/view.search"


没有任何更多的成功。

http://onedrive.github.io/items/search.htm

最佳答案

好的,我终于了解了它是如何工作的。

因此,由于ApiExplorer只是一个示例,因此我们需要手动添加更多功能。

在名为onedriveaccess的模块中,转到包com.microsoft.onedriveaccess.model并添加以下文件ItemList.java

package com.microsoft.onedriveaccess.model;

import com.google.gson.annotations.SerializedName;
import java.util.List;

public class ItemList {
    @SerializedName("value")
    public List<Item> itemList;
}


然后在com.microsoft.onedriveaccess.IOneDriveService.java中,添加以下代码:

@GET("/v1.0/drive/{item-id}/view.search")
@Headers("Accept: application/json")
void searchForItemId(@Path("item-id") final String itemId,
        @QueryMap    Map<String, String> options,
        final Callback<ItemList> itemCallback);


现在我们可以生成搜索查询,如下所示:

  /**
 * The query option to have the OneDrive service expand out results of navigation properties
 */
private static final String EXPAND_QUERY_OPTION_NAME = "expand";

/**
 * Expansion options to get all children, thumbnails of children, and thumbnails
 */
private static final String EXPAND_OPTIONS_FOR_CHILDREN_AND_THUMBNAILS = "children(select=id, name)";


private final Map<String, String> mQueryOptions = new HashMap<>();


private Callback<ItemList> getItemsCallback(final Context context) {
    return new OneDriveDefaultCallback<ItemList>(context) {
        @Override
        public void success(final ItemList items, final Response response) {
            //mItem = items.itemList.get(0);

            //Do what you want to do

            for(Item item: items.itemList){
              Log.v(TAG, "array:"+item.Id+"--- "+item.Name);
            }
        }

        @Override
        public void failure(final RetrofitError error) {

            //Log.v(TAG, "Item Lookup Error: " + mItemId);

        }
    };
}


public void searchQuery(String query){
    mQueryOptions.put(EXPAND_QUERY_OPTION_NAME, EXPAND_OPTIONS_FOR_CHILDREN_AND_THUMBNAILS);
    mQueryOptions.put("q", query);

    final IOneDriveService oneDriveService = oneDriveHelper.getOneDriveService();
    final Callback<ItemList> itemCallback = getItemsCallback(app);
    oneDriveService.searchForItemId(mItemId, mQueryOptions, itemCallback);

}

07-24 20:07