I am developing an application for Android, where I need to get the list of parents of a file taken from google Drive.
I correctly obtain the DriveId using Drive.DriveApi.newOpenFileActivityBuilder(), but when I use DriveResource.listParents I obtain an empty list even if the resource have a parent.
I use the same GoogleApiClient for Drive.DriveApi.newOpenFileActivityBuilder() and DriveResource.listParents, so i do not think that is a scope problem.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.REQUEST_CODE_GOOGLE_DRIVE_FILE_PICKER) {
if (resultCode == RESULT_OK) {
mSelectedFileDriveId = (DriveId) data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
} else {
setResult(Constants.RESULT_CODE_KO);
finish();
}
}
}
...
private ResultCallback<MetadataBufferResult> metadataBufferCallback = new ResultCallback<MetadataBufferResult>() {
@Override
public void onResult(MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
SDKUtils.showMessage(thisActivity, "Impossible salvare l'ultima posizione aperta in Google Drive");
return;
}
MetadataBuffer metadataBuffer = result.getMetadataBuffer();
// HERE I OBTAIN AN EMPTY OBJECT
}
};
...
mGoogleApiClient = new GoogleApiClient.Builder(this)
.setAccountName(driveAccontName)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
...
DriveFile driveFile = Drive.DriveApi.getFile(getGoogleApiClient(), mSelectedFileDriveId);
driveFile.listParents(GoogleApiClient apiClient).setResultCallback(metadataBufferCallback);
Have any suggestions? Thanks!