在我的网页浏览中,我获取了webViewClient方法中的所有网址
public boolean shouldOverrideUrlLoading(WebView view, String url) {}
如果网址来自用户点击,我想将网址投放到其他应用中。否则webview会加载url self。但是我无法区分它们。我该怎么办?
感谢您的帮助!
答案 0 :(得分:3)
我按照How can I get onclick event on webview in android?中的方法。
使用dispatchTouchEvent Android singleTap/OnClick in WebView
有一些替代方法Boolean changedUrl = false;
String currentUrl = null;
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
changedUrl = false;
currentUrl = webView.getUrl();
}
// change either onPageStarted or shouldOverrideUrlLoading
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(changedUrl && !url.equals(currenturl)) {
// page has been clicked
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(changedUrl && !url.equals(currentUrl)) {
// page has been clicked
return true;
}
return false;
}
});
webView.setOnTouchListener( new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.webView && event.getAction() == MotionEvent.ACTION_DOWN){
changedUrl = true;
}
return false;
}
});