Android Google Drive SDK - how to show a list of files in a selected folder

I am trying to get my code to work.

I want my application (at the click of a button) to display all the folders (and files) in the root folder of the drive. But it seems that this is not possible, because despite the fact that I allowed the application using Ouath2, the application has access only to the files and folders that the user selects.

The behavior is strange in that when you open the selection folder, it displays the contents of this folder only if the contents of the ARE are in the folder. It will not list files at all.

Can an expert look at my code and tell me where I am mistaken?

I am using PickFolderWithOpener activity to get the drive id. It returns the identifier of the drive based on the selection of users from the collector.

  DriveId driveId = (DriveId) data.getParcelableExtra( OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID); 

Is that what returns here, the Drive ID folder? Then I need to call the ListFilesInFolderActivity intent. I assume that I need to pass this disk id in the request for intent? If I format DriveID as a string and pass it, it will not work with "Cannot find DriveId. Are you allowed to view this file?" message.

So what I do is pass the ResourceID.

 Intent intent = new Intent(this, ListFilesInFolderActivity.class); intent.putExtra("DriveID", driveId.getResourceId()); startActivity(intent); 

What should be used in ListFilesInFolderActivity? DriveID or resourceID? Here is what I have in 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); } }; 

It seems to work, but it only displays folders in the selected folder. It does not list files. Why folder.listChildren(getGoogleApiClient()) not list files as well ??

I hope this is something obvious that I do not see.

+6
source share
1 answer

You cannot do this with the new SDK, since it only allows SCOPE_FILE access.

Why? Note. Currently, the Google Drive Android API only supports the drive.file and drive.appdata authorization areas. If your application requires additional permissions or features not available in the Android API for Android, you must use the Java API Java API.

+9
source

All Articles