2012-02-02 103 views
2

我在webview(片段)中包含移動谷歌廣告。當您點擊我想在新瀏覽器中打開的廣告時。我已經啓用了以下內容:android webview從Javascript中打開瀏覽器窗口

mWebView.getSettings().setJavaScriptEnabled(true); 
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 

的google.js正在生成的iFrame然而與點擊網頁流量似乎並不作爲一個新的鏈接點擊註冊,並不會調用shouldOverrideUrlLoading

回答

0

找到了回答在另一個這樣的問題here,

但我已經修改它的工作片段(包括getActivity())。 請注意,這是專門爲谷歌廣告。在你的webclient覆蓋下面的方法。

@Override 
     public void onLoadResource(WebView view, String url) 
     { 
      // the url that contains the ad to link to contains googleads, this is risky if google 
      // change it, but there couldn't find a nice way around 
      if (url.contains("googleads")) 
      { 
       HitTestResult hitTestResult = view.getHitTestResult(); 
       // Check is the hit test is a src tag with image anchor (i.e an mobile ad) 
       if (hitTestResult.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) 
       { 
        getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); 
        view.stopLoading();       
       } 
      } 
     } 
相關問題