shouldOverrideUrlLoading无效

时间:2013-03-20 08:12:00

标签: android

在我的应用程序中,未在4.0.3版本上调用 shouldOverrideUrlLoading ()。我已经在2.2和4.0.1上进行了测试,它们都运行良好。 设备名称为 HTC verizon

我的目的是为页面中的mailto:和tel:links提供自定义活动。如果shouldOverrideUrlLoading()永远不会被命中,那么关于如何使其工作的任何想法?

请建议

2 个答案:

答案 0 :(得分:2)

Autoexplicative方法,你也应该覆盖onPageStarted:

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);

    // 11 = Build.VERSION_CODES.HONEYCOMB (Android 3.0)
    if (Build.VERSION.SDK_INT < 11) {

    // According to this page:
    //
    // http://www.catchingtales.com/android-webview-shouldoverrideurlloading-and-redirect/416/
    //
    // shouldOverrideUrlLoading() is not called for redirects on
    // Android earlier than 3.0, so call the method manually.
    //
    // The implementation of shouldOverrideUrlLoading() returns
    // true only when the URL starts with the callback URL and
    // dummyCallbackUrl is true.

         if (shouldOverrideUrlLoading(view, url)) {
             view.stopLoading();
         }
     }
 }

答案 1 :(得分:0)

使用以下方法而不是shouldOverrideUrlLoading()

 private static WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView) findViewById(R.id.web);

        webView.setWebViewClient(new webviewclient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.google.com");

    }
public class webviewclient extends WebViewClient{

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        view.loadUrl(request.toString());
        return true;
    }