How do I work with DriveApi.MetadataBufferResult?

泄露秘密 提交于 2019-12-11 02:59:18

问题


I'm using the Drive API and am starting to get very frustrated. I'm trying to use queries to search for files/folders based on their name. This demo has a good example on how to do this: https://github.com/googledrive/android-demos/blob/master/src/com/google/android/gms/drive/sample/demo/QueryFilesWithAInTitleActivity.java

But I don't want to add the data to a ListView, I just want to extract information from the MetadataBufferResult directly (titles, and IDs so I can work with them). But every example I've looked at only does this ListView thing, and I haven't been able to find a way to extract any information from the MetadataBufferResult or find good documentation on it.

Basically I want to be able to do this (code taken from the demo linked above):

final private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
            new ResultCallback<DriveApi.MetadataBufferResult>() {
                @Override
                public void onResult(DriveApi.MetadataBufferResult result) {
                    if (!result.getStatus().isSuccess()) {
                        showMessage("Problem while retrieving results");
                        return;
                    }

                    //I haven't been able to find a way to do this
                    result.getDriveID();
                    result.getFileTitle();
                }
            };

Short version: I want to search the root directory of someone's Drive account for the file with the title "x" and then read/write to this file. My problem is that I can't extract data from the MetadataBufferResult object I'm passed and all the examples I've seen output it using a ListView which I don't want to do.


回答1:


Try this:

public void onResult(MetadataBufferResult rslt) {
  if (rslt != null && rslt.getStatus().isSuccess()) {
    MetadataBuffer mdb = null;
    try {
      mdb = rslt.getMetadataBuffer();
      if (mdb != null ) for (Metadata md : mdb) {
        if (md == null || !md.isDataValid()) continue;
          md.getTitle(); 
          md.getDriveId();
          md.getAlternateLink();
          //md.get.....();
      }
    } finally { if (mdb != null) mdb.close(); }
  }
}

type 'md. ...' and you'll get the list of metadata available. The full context can be found here

Good Luck



来源:https://stackoverflow.com/questions/32151396/how-do-i-work-with-driveapi-metadatabufferresult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!