Downloading files via HTTP to Android flash disk instead of relying on the browser, for better user experience
Scenario:
When the user hits a list item within the Android ListView control we would like to open a document in this case its a .pdf document from one of our web sites. The website expects a parameter and serves a pdf, matching the parameter in the request. When a file is not available we get a standard 404.
There are times when you just cannot rely on the browser available on Android handsets to open documents for various reasons, one being you want to pop specific error messages on the screen ie document ‘NAME’ is not available yet and some reasons. Our users did not like the passing the control to the browser from the Android application and then reopen the application to get back to where you were.
Solution Discussion
One of the possible solution is to stream the file and write it to and disk and create an activity to open the file on a pdf reader application. PDF readers are shipped with Android which made our lives a lot easier. The small minority who did not have the pdf reader will have problem viewing the file. I am keen to find out how others are handling similar requirements.
Here is the item click handler
This is the function to download and save the pdf file into the disk.
This function itself is simple enough, load a file name and file path and forms a URI.
- Delete any existing file before creating the new file
Comments
Post a Comment