Using Downloadmanager to download file received from applications

753 views Asked by At

Im allowing users selecting and sending xml-file to my app by use of the Share button in other applications, such as Dropbox, Google drive or local file store. (see http://developer.android.com/training/sharing/receive.html)

I can successfully retrieve the URI of the selected/shared file, for instance from Dropbox by:

Uri receivedUri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT));

But how can I download this file to my local filestore with use of Downloadmanager? Am I automatically authenticated on my account, for instance on Dropbox or Google Drive (since I selected and choosed to share the file from theirs mobile apps)? Do I have to configure Downloadmanager differently dependent on what source Im downloading the file from?

Thanks!

1

There are 1 answers

1
Joe Malin On

DownloadManager isn't necessary. Your app can read the file by opening a file descriptor based on the URI, if it's a file URI or a content URI. See ContentResolver.openFileDescriptor(), which returns a ParcelFileDescriptor, which in turn contains a FileDescriptor.

BTW, android.support.v4.content.FileProvider.getUriForFile() will return a content URI for a file under your app's control. Unlike a file URI, you can set temporary access permissions on a content URI. This is much more secure.