2016-11-08 79 views
2

我正在编写一个使用字符串(例如全名=“Adam Smith”)的应用程序,从而在Google Drive中打开相应的“Adam Smith”文件夹。下一步是显示文件夹内的内容。在Google Drive中使用Android Open特定文件夹

其实我现在可以进入谷歌驱动器,但无法进入这个特定的文件夹。任何人都可以为我发布示例代码,因为我阅读了GoogleAPI网页,但无法完成我的应用程序。

我很乐意提前提出建议。谢谢

+0

当你创建一个文件夹或文件时,你会得到一个驱动器。使用它你只能访问文件或文件夹。完整的示例代码在这里https://github.com/googledrive/android-demos/tree/master/app/src/main/java/com/google/android/gms/drive/sample/demo –

回答

1

在此documentation中声明,文件夹为使用DriveFolder.listChildren列出他们的直接子女提供了一种方便的方法。 sample code说明如何列出文件夹中的文件。

public void onConnected(Bundle connectionHint) { 
    super.onCreate(connectionHint); 
    setContentView(R.layout.activity_listfiles); 
    mResultsListView = (ListView) findViewById(R.id.listViewResults); 
    mResultsAdapter = new ResultsAdapter(this); 
    mResultsListView.setAdapter(mResultsAdapter); 
    DriveFolder folder = Drive.DriveApi.getFolder(getGoogleApiClient(), sFolderId); 
    folder.listChildren(getGoogleApiClient()).setResultCallback(childrenRetrievedCallback); 
} 

ResultCallback<MetadataBufferResult> childrenRetrievedCallback = new 
     ResultCallback<MetadataBufferResult>() { 
    @Override 
    public void onResult(MetadataBufferResult result) { 
     if (!result.getStatus().isSuccess()) { 
      showMessage("Problem while retrieving files"); 
      return; 
     } 
     mResultsAdapter.clear(); 
     mResultsAdapter.append(result.getMetadataBuffer()); 
     showMessage("Successfully listed files."); 
    } 

你可以看到更多的例子here

这里有一些相关的SO职位这也可能有助于:

编码愉快!

相关问题