Fetch URL of current page from WebView

断了今生、忘了曾经 提交于 2019-12-20 06:21:39

问题


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:


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



来源:https://stackoverflow.com/questions/11579208/fetch-url-of-current-page-from-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!