Download files on Android

I am in the middle of writing an Android application and want to give my users the opportunity to share their document files.

Ideally, I would like to see files hosted on an HTTP server somewhere, so a user can simply launch their browser on an Android phone, go to the corresponding page, and then upload the file to their phone. I would like my application to be able to open this downloaded file.

I’m not sure that this is possible at all, but, of course, it will be interesting to hear from anyone who knows anything about such things. Unfortunately, I seem to have difficulty answering myself - like most of the rest of the Android SDK, there is a serious lack of documentation.

+6
android download
source share
4 answers

By the way, I came across a reasonable solution that would be easier than messing with intentions and so on ...

The WebView widget allows you to set a DownloadListener object that receives a notification when a WebView is directed to a file of a type that it does not understand. In this way, the functionality that I was after can be achieved by creating a WebView in my application and registering the DownloadListener to listen when the user downloads one of my application document files.

Thank you for your help!

+2
source share

When a user accesses the file you want to support, you can register on Android using IntentFilters to indicate that your application can handle a specific MIME-TYPE.

See the documentation here .

+4
source share

Easy enough to get files from a web server. In your inclusion -

import java.net.URL; import java.net.URLConnection; import java.io.InputStream; 

In your code -

 URL requestURL = new URL(urlStringForFileYouWantToOpen); URLConnection connection = requestURL.openConnection(); InputStream response = connection.getInputStream(); 

Then do what you want using InputStream . I'm not sure if this is close enough to the description of the user downloading the file and then accessing it from your application, but it seems easier for me to get the file in your application.

+3
source share

If you want to integrate the download from the application, then the @jball answer is what you need, if you prefer the process to be initiated through the browser, and then the @Scott answer is what you need. From your description, it looks like you also want users to share documents created with the application, for which your application could upload applications to the web server. Something like WebDAV would be ideal for this, either realized itself using the org.apache.http library, or using one of the open source versions.

0
source share

All Articles