7

I have the following intent:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/*");
startActivityForResult(intent, DBOpenHelper.REQUEST_CODE_RESTORE);

The intent allows the user to select a text file from a number of options. It works fine with local storage and Dropbox for example, and in both cases I can get the file from as follows:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if ((requestCode == DBOpenHelper.REQUEST_CODE_RESTORE)
            && (resultCode == Activity.RESULT_OK)) {
        restoreFile = new File(data.getData().getPath());
        restoreFileName = restoreFile.getName();
    }
}

Local storage works fine and Dropbox will copy a local copy of the file to the SD card and return the correct path. The problem is that if the user to selects files from Google Drive. When they use Google Drive, data.getData().getPath() returns something like: "/document/acc=1;doc=195" instead of returning the path to the locally stored file. How do I have Google Drive download the file and return the path? I want to allow the user to select from any file storage option they have available.

4

1 回答 1

7

当用户选择文件时,Google 云端硬盘可能会或可能不会在本地下载文件。但是,在所有情况下,您都可以通过getContentResolver().openInputStream(data.getData())访问文件的内容- 请注意,它openInputStream()也支持本地文件,并且也可以并且应该在其他情况下使用。

于 2015-01-04T22:26:49.980 回答