当我使用此特定网址= realtor.com
onPageFinished()可以正常工作,但我点击this的搜索按钮时,不能工作,仅仅是因为数据是通过javascript传入的
**WebActivity.java**
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
WebView webView = (WebView) findViewById(R.id.webview1);
webView.setWebChromeClient(new WebChromeClient() { });
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webView.addJavascriptInterface(new MyJavaScriptInterface(),"android");
webView.loadUrl("https://www.realtor.com");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.d("=====", "====Start " + url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d("=====", "=======Finish " + url);
view.loadUrl("javascript:window.android.onUrlChange(window.location.href);");
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.d("=====", "====shouldOverrideUrlLoading " + view.getUrl());
return super.shouldOverrideUrlLoading(view, request);
}
});
}
class MyJavaScriptInterface {
@JavascriptInterface
public void onUrlChange(String url) {
Log.d("hydrated", "onUrlChange" + url);
}
}
}
我的问题是 我只是想以任何方式获取当前网址,我需要知道页面已更改