Android Google Drive SDK - 如何显示选定文件夹中的文件列表 [英] Android Google Drive SDK - how to show list of files in selected folder

查看:112
本文介绍了Android Google Drive SDK - 如何显示选定文件夹中的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望我的应用(单击按钮时)显示所有文件夹(和文件)驱动器的根文件夹。
但似乎这是不可能的,因为即使我已经使用Ouath2授权应用程序,该应用程序只能访问用户选择的文件和文件夹。



这种行为很奇怪,因为当文件夹选取器打开时,如果内容为ARE文件夹,它只会列出该文件夹的内容。它不会列出任何文件。



请问专家请看我的代码并告诉我哪里出错了吗?

我使用 PickFolderWithOpener 活动来获取driveId。它会根据用户在picker中的选择返回一个driveID ..

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

这就是这里返回的文件夹的驱动器ID吗?然后我需要调用intent ListFilesInFolderActivity 。我假设我必须在意图调用中传递此driveID?如果我将DriveID格式化为字符串并将其传递给它,则它会失败
,并显示Can not find DriveId。You are authorized to view this file?消息。



所以我在做的是传递ResourceID。

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

需要在 ListFilesInFolderActivity中使用什么? DriveID或resourceID?这是我在 ListFilesInFolderActivity?

  Bundle extras = getIntent ().getExtras(); 
folderId = extras.getString(DriveID); //这是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(无法找到DriveId。您有权查看此文件吗?);
return;
}
DriveFolder文件夹= Drive.DriveApi.getFolder(getGoogleApiClient(),result.getDriveId());
showMessage(Result driveId is:+ result.getDriveId());
folder.listChildren(getGoogleApiClient())
.setResultCallback(metadataResult);



}
};

这似乎有效,但它只列出选定文件夹中的文件夹。它不会列出这些文件。
为什么 folder.listChildren(getGoogleApiClient())不会列出这些文件!?

希望这是明显的我缺少的东西。

解决方案

你不能用新的SDK来做这件事,因为它只允许SCOPE_FILE访问。 p>

这是为什么? 注意:Google Drive Android API目前仅支持drive.file和drive.appdata授权范围,如果您的应用程序需要其他权限或Drive Android API尚未提供的功能,则必须使用Google API Java Client。


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."

这篇关于Android Google Drive SDK - 如何显示选定文件夹中的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆