2011-12-27 9 views
1

높이 60dp의 webview를 사용하고 있으며, 로컬 HTML 파일을 전달하고 있습니다. 기본적으로 webview에서 링크를 클릭하면 브라우저가 열립니다. 그러나 이상하게도 그는 웹보기에, 나는 또한 웹보기 클라이언트와 의도를 통해 브라우저를 기본값으로 응답 URL을 통과하려고 시도와 링크를 열리지 만 소용 .. URL을 webview에서 브라우저로 전달하려고합니다.

내 코드 :

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

현재 웹보기로드를 중지합니다.

ad.getSettings().setSupportMultipleWindows(false); 

편집 :

가 크롬을 연결하십시오

@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; 
     } 

은 또한 당신의 웹보기에 대한 설정을 추가하는 동안이 추가 : 광고가 웹보기의 대상이기 때문에, 이런 식으로 일을보십시오 고객에게 웹뷰를 확인한 다음 확인하십시오 :

ad.setWebChromeClient(new MyWebChromeClient()); 

희망이 당신을 위해 작동합니다.

+0

감사합니다 답변 Usama Sarwar,하지만 불행히도 그것은 내 문제를 해결하지 못합니다. 내가로드 할 때 advertising.html 파일을 볼 수있는 광고에 해당 링크가있는 광고를 생성하는 자바 스크립트 코드가 있습니다. 웹 뷰에서 하이퍼 링크를 열려고 할 때 코드와 코드가 작동하지만 "WebViewClient"의 sysout은 어떤 경우에도 인쇄되지 않습니다. –

+0

내 수정 된 게시물을 확인하십시오. 도움이 될 것입니다. –

+0

답장을 보내 주셔서 감사합니다. 이제 다른 html 파일을 사용하고 있으며 문제가 해결되었습니다. –

관련 문제