2016-10-24 3 views
0

나는 사용자 정의 webview 클라이언트와 함께 webview 있습니다. 내가 가진 요청을 차단하고 있습니다 :Android webview - URL을 건너 뛰는 방법?

때때로
@Override 
public WebResourceResponse shouldInterceptRequest(WebView view, String url) { 
    // ... 
} 

I는 링크의 형태로 웹보기에서 사용자 정의 이벤트에 대한 정보를 얻고있다 :

XYZ : // 할 무언가

웹뷰를 무시하고 싶습니다. 하지만 'shouldInterceptRequest'는 무언가를 반환해야하고 내 페이지 대신 'null'을 반환하면 'unknown url xyz : // do-something'이라고 표시됩니다. 어떻게 처리 할 수 ​​있습니까? 어떻게 링크를 차단할 수 있지만 webview 측면에서 작업을 해제 할 수 있습니까?

답변

0

사용자가있는 사이트와 이동하려는 사이트에서 문자열 비교 만하면됩니다.

public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     if (Uri.parse(url).getHost().equals("www.example.com")) { 
      // This is my web site, so do not override; let my WebView load the page 
      return false; 
     } 
     // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(intent); 
     return true; 
    } 
+0

내가 '공공 부울 shouldOverrideUrlLoading (웹보기보기, 문자열 URL)를'사용할 수 없습니다, 그것은 '공공 WebResourceResponse shouldInterceptRequest (웹보기보기, 문자열 URL을)'이어야한다. – user5981074