2011-12-27 52 views
1

我正在使用高度60dp的webview,我傳遞一個本地html文件到它,默認情況下,當我點擊一個鏈接,它必須打開瀏覽器。但奇怪的是它的開放與web視圖,我也嘗試過的WebView客戶端,並試圖通過響應URL默認意圖通過瀏覽器的聯繫,但不成功..試圖從webview到瀏覽器的URL

我的代碼片段:

WebViewClient yourWebClient = new WebViewClient() 
     { 

      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) 
      { 
       System.out.println("Inside WebViewClient the URL is....."+url); 

       Intent i = new Intent(Intent.ACTION_VIEW); 
       i.setData(Uri.parse(url)); 
       startActivity(i); 

      return true; 
      } 
     }; 

    WebView ad = (WebView) findViewById(R.id.webview1); 
    ad.getSettings().setJavaScriptEnabled(true); 
    ad.loadUrl(feed.getItem(position).getLink()); 
    ad.getSettings().setLoadWithOverviewMode(true); 
    ad.getSettings().setUseWideViewPort(true); 
    ad.setInitialScale(100); 
     ad.setWebViewClient(yourWebClient); 
    ad.loadUrl("file:///android_asset/advertisement.htm"); 

回答

1

停止當前的webview加載。由於廣告的WebView對象,嘗試做這種方式:

@Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) 
     { 
      System.out.println("Inside WebViewClient the URL is....."+url); 

      ad.stopLoading(); 
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
      startActivity(intent); 

     return true; 
     } 

另外補充這一點的同時增加對您的WebView設置:

ad.getSettings().setSupportMultipleWindows(false); 

編輯:

嘗試關聯鉻客戶端與您的webview然後檢查:

ad.setWebChromeClient(new MyWebChromeClient()); 

希望這個爲你工作。

+0

謝謝你的答案烏薩馬薩瓦爾,但不幸的是,它不能解決我的問題。如果您看到我正在加載的ads.html文件有一個來自Google的Java腳本代碼,它會生成帶有相應廣告鏈接的廣告。您的代碼和我的代碼在嘗試從webview中打開超鏈接時會起作用,但「WebViewClient」中的系統輸出不會在任何情況下進行打印。 –

+0

檢查我編輯的帖子。這可能有幫助。 –

+0

感謝您的回覆,現在我正在使用不同的html文件,並解決了我的問題。 –