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.
Goto the same Google Sheets File and refresh the page. Then you will get the "List Files/Folders" menu, click on it, and select the "List All Files and Folders" item.
To switch from grid view to list view, open Google Drive and press the List view button. Note: Smartbar features are available in the Google Drive file preview for Google files and non-Google files. You can access the file preview directly from grid mode.
Each user has a "root" folder called "My Drive" that functions as their primary hierarchy, and consists of everything that descends from this root folder. The user is the primary owner of this folder. Shared drives. A shared drive is an organizational structure within Google Drive that lives parallel to My Drive.
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With