Hi,

I want to create a little browser, which should also be able to save images.

I managed to implement a webview where I can save the images via a long 
click context menu/HitTestResult. So when I get the URL of an image, I do 
something like this:

    URL url = new URL(yourImageUrl);
      InputStream is = (InputStream) url.getContent();
      byte[] buffer = new byte[8192];
      int bytesRead;
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      while ((bytesRead = is.read(buffer)) != -1) {
        output.write(buffer, 0, bytesRead);
      }

then put the output.toByteArray() into a FileOutputStream;

For "normal" sites this works fine, images are stored on the sdcard.

But I still don't know how to download an image of a site which requires 
some kind of authentication. For example, I enter the site and input a 
username/password into a form (some server side language like PHP), which 
brings me to some pictures. The webview has no problem in logging in and 
displaying everything. But I can't save images, since the authentication - 
which is present in the webview - is *not* present in my image saving 
mechanism.

With the above code I simply get a FileNotFoundException on the 
URL.getContent(). Then I tried to use HttpClient and HttpGet/HttpResponse, 
where the response is always code 403.

My question: How can I access/download/authenticate to get images of 
protected areas (may it be through server side language or basic 
authentication).

I mean... it's all there, displayed correctly and authenticated in the 
WebView :-( But there's no connection between the content of the WebView 
and my URL/Http Request downloading efforts. 

So, the webview already has all the information of the authentication. But 
when I set up a HttpClient for Downloading, I either have to 

- fetch the right session cookies from the WebView (but HOW can *I *know 
what cookies for which URLS have been added to the webview,  when there's 
no getAllCookies() method but just a getCookie(String url) method)?

- for basic authentication, get the Username & password, when I don't know 
the realm of the website?

Can the webview somehow share it's authentication state (easily)?

-- 
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