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