Intent.ACTION_GET_CONTENT with Google Drive

I have the following intention:

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

The target allows the user to select a text file from several parameters. It works fine with local storage and Dropbox, for example, and in both cases I can get the file 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 the local copy of the file to the SD card and return the correct path. The problem is that if the user 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 download a Google Drive file and return it? I want to allow the user to select from any file storage file available to them.

+7
android android-intent google-drive-sdk
source share
1 answer

A Google Drive may or may not be loaded locally when the user selects a file. However, in all cases, you can access the contents of the file through getContentResolver (). OpenInputStream (data.getData ()) - note that openInputStream() also supports local files, and can and should be used in other cases.

+6
source share

All Articles