Rectangle 27 1

I have a similar problem to yours. The issue here is how WebView handles attachments (a real pain in the ass). When the WebView visits a web page that at some point returns an attachment, it says kinda like "Oh crap, what can I do with this non-HTML thingy?... Ey you! DownloadListener! do something with this URL that is saying some nonsense about an attachment". So, the DownloadListener takes over and here is the problem: it requests again the same URL to download the attachment, so, for downloading an attachment when visiting a page, the WebView perfoms 2 requests: the page itself and then another one to download the attachment, instead of just downloading it.

And how is this a problem? Well, let's say that in your abc.com/xyz.php you have some logic like:

<?php
   if(User::loggedIn()) {
       header("Content-Disposition: attachment...");
       //Some more logic for the download
   }
?>

The second request performed by the DownloadListener will make another request to abc.com/xyz.php but this time it won't contain cookies or session information so it won't enter the "download" logic.

A possible solution would be to redirect to a temporal copy or the real path to the file that doesn't contains any logic so there is no problem. Of course, you also need to define your Download listener withing your WebView, something like this for example.

webView.setDownloadListener(new DownloadListener() {

    @Override
    public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {

        final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        Request request = new DownloadManager.Request(Uri.parse(url));
        request.setMimeType(mimeType);

        //Persist download notification in the status bar after the download completes (Android 3.0+)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }

        dm.enqueue(request);
    }

});

Android browser/webview bug? Content-Disposition: attachment; filename...

android webview download content-disposition
Rectangle 27 0

I have solved same problem in android eclipse, first i have created a webview then added downloadListner, after that i am checking either machine is connected to the internet or not, if so, the URL is loaded into webview, else an error message appears "No Network", That's it. You can check the code below which i am using in my app.

@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView wv = (WebView) findViewById(R.id.webView1);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.setWebViewClient(new WebViewClient());
        wv.setDownloadListener(new DownloadListener()
        {
            public void onDownloadStart(String url, String userAgent,StringcontentDisposition, String mimetype,long contentLength) 
            {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);   
            }
        });
        ConnectivityManager connMgr = (ConnectivityManager)
        this.getSystemService(Context.CONNECTIVITY_SERVICE);

        final android.net.NetworkInfo wifi =
        connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        final android.net.NetworkInfo mobile =
        connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if( wifi.isAvailable() )
        {
            wv.loadUrl("http://www.example.com");
        }
        else if( mobile.isAvailable() )
        {
            wv.loadUrl("http://www.example.com");
        }
        else
        {
            Toast.makeText(this, "No Network " , Toast.LENGTH_LONG).show();
        }        
    }
}

Android WebView Download Listener - Stack Overflow

android android-webview
Rectangle 27 0

Well the blinking you see is cause is loading again the data and generating the view, saw for you maybe is just a little blink but if you but more thing in it or you add some downloading or streaming for each view, that blink will become in a white page loading. What you can do is on the page changed listener you should add code to set the current zoom level on the last webview.

lastPos = pos - 1;
((WebView) mPager.getChildAt(lastPos)).getSettings().setDefaultZoom(zoomLevel);

NOTE: This is just an EXAMPLE, maybe you have to change something depending on your configuration before this can work with your code.

this example assumes that the WebView is the only child of each page from the viewpager, if you have more or if the WebView is inside a relative or linear layout, then you will have to add the code to retrieve the WebView and the apply the change on the zoom.

If you want the image to take all the screen inside the webview, you can do this. in this case "web" is my object of type "WebView". Good luck.

web.loadData("<html><head></head><body><img src='" + url //IMAGE URL
+ "' style='width:100%;height:98%;max-width:100%;max-height:98%;'></body></html>",
"text/html", "utf-8"); //THIS WILL FIT THE IMAGE TO TAKE ALL THE SCREEN

I managed to make this one work: '((ExtendedWebView) mPager.getChildAt(pos)).loadDataWithBaseURL(null, data, "text/html", "UTF-8", null);' I'm using css to make the image fit the screen (but it's not working) like this: 'String data = "<div>" + "<table width=\"100%\" height=\"100%\">" + "<tr><td style=\"vertical-align:middle; text-align:center; margin:0px\">" + "<img src=\""+ url + "\"/>" + "</td></tr>" + "</table>" + "</div>";'

Well seeing your code seems like you are not setting the image to take the fill width or height of the table, you are just setting the table to take the full screen, BUT you need to specify to the img tag that he also needs to take the full size of the table, and when dealing with images is better to also specify a max-width and max-height. One more thing, if you want to do it right stop using tables to arrange things, you better use css, you only need a img tag for this to work. Ex. <html><head></head><body><img src="" style=""></body></html> and that's it. Good luck

It's not working. I'm trying something like this: '"<img src=\"" + url + "\" style=\"width:"+scrWidth +"px; vertical-align:middle; text-align:center; margin:0px\">' scrWidth is width of the screen in pixels.

i already made a working example and added the code to load the URL in my answer.

webview - Android: How to ZoomOut a single page in ViewPager if user z...

android webview android-viewpager
Rectangle 27 0

You could start the progressbar by making it visible, then download. Rather than just start a browser, though, I would load the page into a WebView. I would override the WebView and set a onPageFinished() listener within which I would stop the progressBar

m opening a faceapp, and as far as i saw, since october 2013 facebook kind block their apps from open on webviews.. so i droped this and i

Android - Load a progress bar while BROWSER loads a page (NO WEBVIEW) ...

android browser progress-bar