2

I am programming an app that use a string (e.g. full name = "Adam Smith") and thus open corresponding "Adam Smith" folder in google drive. The next step is to show the content inside the folder.

Actually I am now able to access into google drive but unable to go into this specific folder. Can anyone post a sample code for me since I read the GoogleAPI webpage but cannot finish my app.

I am appreciated for suggestion in advance. Thank you

Michael
  • 23
  • 1
  • 5
  • When you create a folder or file in that you will get a driveid .Using that only you can access the file or folder. complete sample code are here https://github.com/googledrive/android-demos/tree/master/app/src/main/java/com/google/android/gms/drive/sample/demo – Narender Reddy Nov 09 '16 at 12:43

1 Answers1

1

It is stated in this documentation that Folders provide a convenience method for listing their direct children using DriveFolder.listChildren. The sample code illustrates how to list files in a folder.

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.");
    }

You can see more examples here.

Here are some related SO posts which might also help:

Happy coding!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59