如何访问共享文件 [英] How to access shared file

查看:168
本文介绍了如何访问共享文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andorid应用程序,我想访问只有那些与我或者通过网络(drive.google.com)或应用程序共享文件。我使用谷歌驱动的API来访问共享文件,但我不能访问任何文件或文件夹与我分享。我的code如下。

In my Andorid app, I want to access only those file which is shared with me either by web(drive.google.com) or app. I am using google drive API to access shared file but I am not able to access any file or folder shared with me. My code is given below.

public class QueryFilesSharedWithMeActivity extends BaseDemoActivity {

private ListView mResultsListView;
private ResultsAdapter mResultsAdapter;

@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);
    setContentView(R.layout.activity_listfiles);
    mResultsListView = (ListView) findViewById(R.id.listViewResults);
    mResultsAdapter = new ResultsAdapter(this);
    mResultsListView.setAdapter(mResultsAdapter);
}

/**
 * Clears the result buffer to avoid memory leaks as soon as the activity is no longer
 * visible by the user.
 */
@Override
protected void onStop() {
    super.onStop();
    mResultsAdapter.clear();
}

@Override
public void onConnected(Bundle connectionHint) {
    super.onConnected(connectionHint);
    Query query = new Query.Builder()
            .addFilter(Filters.sharedWithMe())
            .build();
    Drive.DriveApi.query(getGoogleApiClient(), query)
            .setResultCallback(metadataCallback);
}

final private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
        new ResultCallback<DriveApi.MetadataBufferResult>() {
            @Override
            public void onResult(DriveApi.MetadataBufferResult result) {
                if (!result.getStatus().isSuccess()) {
                    showMessage("Problem while retrieving results");
                    return;
                }
                mResultsAdapter.clear();
                mResultsAdapter.append(result.getMetadataBuffer());
            }
        };

}

注*我们可以用一个特定的文件夹名称进行筛选与我共享的文件或文件夹?

Note* Can we filter a file or folder shared with me with a specific folder name?

推荐答案

是您的应用程序授权访问共享文件?
目前,谷歌云端硬盘Android API仅支持文件范围的访问(详情请参阅这里)。所以,如果您的应用程序没有被授权访问这些共享文件,您将不会收到他们在查询结果。

Is your app authorized to access the shared files? Currently Google Drive Android API only supports FILE scope access (see details here). So if your app is not authorized to access those shared files, you won't receive them in the query result.

这篇关于如何访问共享文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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