Fetch URL of current page from WebView

2020-05-07 15:00发布

I have a link which contains collection of books (for eg. www.bookstore.com), from which I select one book (with URL www.bookstore.com/book1.epub) which should be downloaded to my library when user clicks on Download button of that book.

I'm done with download part but what is bothering to me is How will I get the URL of specific book which has been selected by user to download i.e. www.bookstore.com/book1.epub ?

I tried with webView.getUrl(), but it doesn't get fired at all except for first load when it's null.

Any help appreciated.

1条回答
Anthone
2楼-- · 2020-05-07 15:29

You just need to implement WebViewClient.

Where inside shouldOverrideUrlLoading(), you will be having current URL:

@Override  
public boolean shouldOverrideUrlLoading(WebView view, String url) {  
        // TODO Auto-generated method stub  

       // Log.d("URL => ", url);    // current URL
       view.loadUrl(url);  
       return true;  
 }  

Read more about WebView and WebViewClient => WebView | Android Developer

查看更多
登录 后发表回答