The problem - I try to list the files/folders in google drive with their API from my android app but the list is always empty.
1. I know I'm connected. The listFiles
method is called from the onConnected
callback of the GoogleApiClient
object.
2. The MetadataBuffer
object is not null.
3. Please please help
private void listFiles() {
DriveFolder folder = Drive.DriveApi.getRootFolder(googleApiClient);
folder.listChildren(googleApiClient).setResultCallback(metadataResult);
}
final private ResultCallback<DriveApi.MetadataBufferResult> metadataResult = new
ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
Log.d(TAG, "Problem while retrieving files");
return;
}
MetadataBuffer mdb = result.getMetadataBuffer();
for (Metadata md : mdb) {
Log.d(TAG, md.getTitle());
Log.d(TAG, md.getAlternateLink());
}
// Also tried this way
Iterator<Metadata> iterator = result.getMetadataBuffer().iterator();
while(iterator.hasNext()) {
Log.d(TAG, iterator.next().getTitle());
}
}
};
So in case someone needs this in future,
Apparently you will see only the files in folders that your app created. That's why when you login for the first time and try to list the files you won't see anything.
Thanks @seanpj for the heads up.
P.S. Maybe it's a permissions thing though...