Hi

So, the solution was to extract the filename from
setDownloadListener()
and to manage the download with an AsyncTask using an
HttpUrlConnection.

8< - - - - - - -  [from the AsyncTask doInBackground() method]
...

// Store call parameters
URL url = new URL(params.source_url);
String target_file_path = params.destination_file_path;

// Open the URL
HttpURLConnection uconn = (HttpURLConnection)url.openConnection();
uconn.setConnectTimeout(20000);
uconn.setReadTimeout(10000);
uconn.setDoInput(true);
uconn.connect();

// used later to update a 0-100% progress bar
int lenghtOfFile = uconn.getContentLength();

// downlod the file
BufferedInputStream input = new BufferedInputStream(url.openStream(),
8192);
OutputStream os = new FileOutputStream(target_file_path);
BufferedOutputStream output = new BufferedOutputStream(os, 8192);
...
8< - - - - - - -

best :)

--
Mathieu



On Sep 30, 2:31 pm, bdk <[email protected]> wrote:
> Ok, I'm possibly a step closer to the solution:
>
> (thanks to this 
> post:http://groups.google.com/group/android-developers/browse_thread/threa...
> )
>
> mWebView.setDownloadListener(new DownloadListener()
> {
>     public void onDownloadStart(String url, String userAgent,
>             String contentDisposition, String mimetype,
>             long contentLength)
>     {
>         Log.i("OF", "onDownloadStart(): " + " url = " + url );
>         Log.i("OF", " userAgent = " + userAgent );
>         Log.i("OF", " contentDisposition = " + contentDisposition );
>         Log.i("OF", " mimetype = " + mimetype );
>         Log.i("OF", " contentLength (KB) = " + (contentLength /
> 1024.0) );
>     }
>
> });
>
> from this one I can retrieve an easier to parse
> "contentDisposition" (no cryptic symbols/encodings)
>
> now the question is: how do I move on to starting a custom download?
> I'll show a progress-bar and the file will be downloaded to
> apredefined folder.
>
> Is there any other higher level function available or shall I base the
> download code on HTTP Get?
>
> thanks
>
> --
> Mathieu
>
> On Sep 30, 1:21 pm,bdk<[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi
>
> > I'm in the following situation: I'm using a WebView in an application
> > to allow the download of files stored in a phpBB forum.
> > I need to directly handle the downloads, saving the files to the
> > application folders with their original names.
>
> > I'm bound to Android 2.2 Froyo, so no DownloadManager (if it even
> > helps:http://www.vogella.de/blog/2011/06/14/android-downloadmanager-example/
> > ).
>
> > So, the problem is that the download links for the files are like
> > this:
>
> >  http://mywebsite.com/download/file.php?id=123
>
> > These links get caught by shouldOverrideUrlLoading(), but I can't
> > handle the download in a custom way since there's no actual "file path
> > and name on the server".
>
> > I tried to use an HttpURLConnection and checked the returned headers.
> > I located the file name in the "Content-disposition" header value,
> > which is something like:
>
> > attachment; filename*=UTF-8''the%20file%20name%20on%20the%20server.aaa
>
> > Seems like phpBB generates this HTML response header here:
> >  https://github.com/phpbb/phpbb3/blob/develop/phpBB/download/file.php#...
> > which refers to:
> >  https://github.com/phpbb/phpbb3/blob/develop/phpBB/includes/functions...
> >   more 
> > specificallyhttps://github.com/phpbb/phpbb3/blob/develop/phpBB/includes/functions...
>
> > So, WebView alone does not seem able to handle this kind of "Content-
> > disposition" HTTP response header.
>
> > It must be noted that these phpBB "file.php?id=123" links do work in
> > the BrowserActivity that comes with each Android OS, and the correct
> > file name pops up in the "save as..." dialog.
>
> > ATM I'm digging in BrowserActivity.java present in Android's
> > sourcecode repository...
>
> > I saw that I might be good to go by using the InputStream returned by
> > an HttpURLConnection, as in e.g.:
>
> >  http://getablogger.blogspot.com/2008/01/android-download-image-from-s...
> >  http://www.helloandroid.com/tutorials/how-download-fileimage-url-your...
>
> > In the case that this is the only solution a question remains: how do
> > I retrieve the original filename?
> > Parsing the "Content-disposition" header value? :S
>
> > any hint is appreciated!
> > thanks
>
> > --
> > Mathieu

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to