I am struggling to get my code to work.
I want my app (when a button is clicked) to show all the folders (and files) in the root folder of the drive. But it seems this is not possible since even though I have authorised the app using Ouath2, the app only has access to the files and folder that the user selects.
The behaviour is strange in that when the folder picker opens, it only lists the contents of that folder if the contents ARE folders. It will not list any files at all.
Could an expert please look at my code and tell me where I am going wrong?
I am using the PickFolderWithOpener
activity, in order to get the driveId. It returns a driveID based on the users selection from the picker..
DriveId driveId = (DriveId) data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
Is that is what is returned here, the folder Drive ID? I then need to call the intent ListFilesInFolderActivity
. I assume I have to pass this driveID in the intent call? If I format the DriveID as a string and pass it, it fails
with the "Cannot find DriveId. Are you authorized to view this file?" message.
So what I am doing is passing the ResourceID.
Intent intent = new Intent(this, ListFilesInFolderActivity.class);
intent.putExtra("DriveID", driveId.getResourceId());
startActivity(intent);
What needs to be used in the ListFilesInFolderActivity?
The DriveID or resourceID? Here is what I have in the ListFilesInFolderActivity?
Bundle extras = getIntent().getExtras();
folderId= extras.getString("DriveID"); // this is the resourceID
Drive.DriveApi.fetchDriveId(getGoogleApiClient(), folderId)
.setResultCallback(idCallback);
final private ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
@Override
public void onResult(DriveIdResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Cannot find DriveId. Are you authorized to view this file?");
return;
}
DriveFolder folder = Drive.DriveApi.getFolder(getGoogleApiClient(), result.getDriveId());
showMessage("Result driveId is: " + result.getDriveId());
folder.listChildren(getGoogleApiClient())
.setResultCallback(metadataResult);
}
};
Which seems to work, but it only lists folders in the selected folder. It does not list the files.
Why does folder.listChildren(getGoogleApiClient())
not list the files also!?
Hopefully this is something obvious I am missing.
You cannot do this with the new SDK as it only allows SCOPE_FILE access.
Is this why?? "Note: The Google Drive Android API currently only supports drive.file and drive.appdata authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client."
来源:https://stackoverflow.com/questions/22859425/android-google-drive-sdk-how-to-show-list-of-files-in-selected-folder