WebViewClient | API reference | Android Developers (original) (raw)
public class WebViewClientextends [Object](/reference/java/lang/Object) ``
Summary
| Constants | |
|---|---|
| int | ERROR_AUTHENTICATION User authentication failed on server |
| int | ERROR_BAD_URL Malformed URL |
| int | ERROR_CONNECT Failed to connect to the server |
| int | ERROR_FAILED_SSL_HANDSHAKE Failed to perform SSL handshake |
| int | ERROR_FILE Generic file error |
| int | ERROR_FILE_NOT_FOUND File not found |
| int | ERROR_HOST_LOOKUP Server or proxy hostname lookup failed |
| int | ERROR_IO Failed to read or write to the server |
| int | ERROR_PROXY_AUTHENTICATION User authentication failed on proxy |
| int | ERROR_REDIRECT_LOOP Too many redirects |
| int | ERROR_TIMEOUT Connection timed out |
| int | ERROR_TOO_MANY_REQUESTS Too many requests during this load |
| int | ERROR_UNKNOWN Generic error |
| int | ERROR_UNSAFE_RESOURCE Resource load was canceled by Safe Browsing |
| int | ERROR_UNSUPPORTED_AUTH_SCHEME Unsupported authentication scheme (not basic or digest) |
| int | ERROR_UNSUPPORTED_SCHEME Unsupported URI scheme |
| int | SAFE_BROWSING_THREAT_BILLING The resource was blocked because it may trick the user into a billing agreement. |
| int | SAFE_BROWSING_THREAT_MALWARE The resource was blocked because it contains malware. |
| int | SAFE_BROWSING_THREAT_PHISHING The resource was blocked because it contains deceptive content. |
| int | SAFE_BROWSING_THREAT_UNKNOWN The resource was blocked for an unknown reason. |
| int | SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE The resource was blocked because it contains unwanted software. |
| Public constructors |
|---|
| WebViewClient() |
| Public methods | |
|---|---|
| void | doUpdateVisitedHistory(WebView view, String url, boolean isReload) Notify the host application to update its visited links database. |
| void | onFormResubmission(WebView view, Message dontResend, Message resend) As the host application if the browser should resend data as the requested page was a result of a POST. |
| void | onLoadResource(WebView view, String url) Notify the host application that the WebView will load the resource specified by the given url. |
| void | onPageCommitVisible(WebView view, String url) Notify the host application that WebView content left over from previous page navigations will no longer be drawn. |
| void | onPageFinished(WebView view, String url) Notify the host application that a page has finished loading. |
| void | onPageStarted(WebView view, String url, Bitmap favicon) Notify the host application that a page has started loading. |
| void | onReceivedClientCertRequest(WebView view, ClientCertRequest request) Notify the host application to handle a SSL client certificate request. |
| void | onReceivedError(WebView view, int errorCode, String description, String failingUrl) This method was deprecated in API level 23. Use onReceivedError(WebView, WebResourceRequest, WebResourceError) on Build.VERSION_CODES.M and above. |
| void | onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) Report web resource loading error to the host application. |
| void | onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) Notifies the host application that the WebView received an HTTP authentication request. |
| void | onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) Notify the host application that an HTTP error has been received from the server while loading a resource. |
| void | onReceivedLoginRequest(WebView view, String realm, String account, String args) Notify the host application that a request to automatically log in the user has been processed. |
| void | onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) Notifies the host application that an SSL error occurred while loading a resource. |
| boolean | onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) Notify host application that the given WebView's render process has exited. |
| void | onSafeBrowsingHit(WebView view, WebResourceRequest request, int threatType, SafeBrowsingResponse callback) Notify the host application that a loading URL has been flagged by Safe Browsing. |
| void | onScaleChanged(WebView view, float oldScale, float newScale) Notify the host application that the scale applied to the WebView has changed. |
| void | onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) This method was deprecated in API level 15. This method is no longer called. When the WebView encounters a redirect loop, it will cancel the load. |
| void | onUnhandledKeyEvent(WebView view, KeyEvent event) Notify the host application that a key was not handled by the WebView. |
| WebResourceResponse | shouldInterceptRequest(WebView view, WebResourceRequest request) Notify the host application of a resource request and allow the application to return the data. |
| WebResourceResponse | shouldInterceptRequest(WebView view, String url) This method was deprecated in API level 21. Use shouldInterceptRequest(WebView, WebResourceRequest) on Build.VERSION_CODES.M and above. |
| boolean | shouldOverrideKeyEvent(WebView view, KeyEvent event) Give the host application a chance to handle the key event synchronously. |
| boolean | shouldOverrideUrlLoading(WebView view, WebResourceRequest request) Give the host application a chance to take control when a URL is about to be loaded in the current WebView. |
| boolean | shouldOverrideUrlLoading(WebView view, String url) This method was deprecated in API level 24. Use shouldOverrideUrlLoading(WebView, WebResourceRequest) on Build.VERSION_CODES.N and above. |
| Inherited methods |
|---|
| From class java.lang.Object Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. finalClass<?> getClass() Returns the runtime class of this Object. int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. final void wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
Constants
ERROR_AUTHENTICATION
public static final int ERROR_AUTHENTICATION
User authentication failed on server
Constant Value: -4 (0xfffffffc)
ERROR_BAD_URL
public static final int ERROR_BAD_URL
Malformed URL
Constant Value: -12 (0xfffffff4)
ERROR_CONNECT
public static final int ERROR_CONNECT
Failed to connect to the server
Constant Value: -6 (0xfffffffa)
ERROR_FAILED_SSL_HANDSHAKE
public static final int ERROR_FAILED_SSL_HANDSHAKE
Failed to perform SSL handshake
Constant Value: -11 (0xfffffff5)
ERROR_FILE
public static final int ERROR_FILE
Generic file error
Constant Value: -13 (0xfffffff3)
ERROR_FILE_NOT_FOUND
public static final int ERROR_FILE_NOT_FOUND
File not found
Constant Value: -14 (0xfffffff2)
ERROR_HOST_LOOKUP
public static final int ERROR_HOST_LOOKUP
Server or proxy hostname lookup failed
Constant Value: -2 (0xfffffffe)
ERROR_IO
public static final int ERROR_IO
Failed to read or write to the server
Constant Value: -7 (0xfffffff9)
ERROR_PROXY_AUTHENTICATION
public static final int ERROR_PROXY_AUTHENTICATION
User authentication failed on proxy
Constant Value: -5 (0xfffffffb)
ERROR_REDIRECT_LOOP
public static final int ERROR_REDIRECT_LOOP
Too many redirects
Constant Value: -9 (0xfffffff7)
ERROR_TIMEOUT
public static final int ERROR_TIMEOUT
Connection timed out
Constant Value: -8 (0xfffffff8)
ERROR_TOO_MANY_REQUESTS
public static final int ERROR_TOO_MANY_REQUESTS
Too many requests during this load
Constant Value: -15 (0xfffffff1)
ERROR_UNKNOWN
public static final int ERROR_UNKNOWN
Generic error
Constant Value: -1 (0xffffffff)
ERROR_UNSAFE_RESOURCE
public static final int ERROR_UNSAFE_RESOURCE
Resource load was canceled by Safe Browsing
Constant Value: -16 (0xfffffff0)
ERROR_UNSUPPORTED_AUTH_SCHEME
public static final int ERROR_UNSUPPORTED_AUTH_SCHEME
Unsupported authentication scheme (not basic or digest)
Constant Value: -3 (0xfffffffd)
ERROR_UNSUPPORTED_SCHEME
public static final int ERROR_UNSUPPORTED_SCHEME
Unsupported URI scheme
Constant Value: -10 (0xfffffff6)
SAFE_BROWSING_THREAT_BILLING
public static final int SAFE_BROWSING_THREAT_BILLING
The resource was blocked because it may trick the user into a billing agreement.
This constant is only used when targetSdkVersion is at least [Build.VERSION_CODES.Q](/reference/android/os/Build.VERSION%5FCODES#Q). Otherwise, [SAFE_BROWSING_THREAT_UNKNOWN](/reference/android/webkit/WebViewClient#SAFE%5FBROWSING%5FTHREAT%5FUNKNOWN) is used instead.
Constant Value: 4 (0x00000004)
SAFE_BROWSING_THREAT_MALWARE
public static final int SAFE_BROWSING_THREAT_MALWARE
The resource was blocked because it contains malware.
Constant Value: 1 (0x00000001)
SAFE_BROWSING_THREAT_PHISHING
public static final int SAFE_BROWSING_THREAT_PHISHING
The resource was blocked because it contains deceptive content.
Constant Value: 2 (0x00000002)
SAFE_BROWSING_THREAT_UNKNOWN
public static final int SAFE_BROWSING_THREAT_UNKNOWN
The resource was blocked for an unknown reason.
Constant Value: 0 (0x00000000)
SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE
public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE
The resource was blocked because it contains unwanted software.
Constant Value: 3 (0x00000003)
Public constructors
WebViewClient
public WebViewClient ()
Public methods
doUpdateVisitedHistory
public void doUpdateVisitedHistory (WebView view, String url, boolean isReload)
Notify the host application to update its visited links database.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| url | String: The url being visited. |
| isReload | boolean: true if this url is being reloaded. |
onFormResubmission
public void onFormResubmission (WebView view, Message dontResend, Message resend)
As the host application if the browser should resend data as the requested page was a result of a POST. The default is to not resend the data.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| dontResend | Message: The message to send if the browser should not resend |
| resend | Message: The message to send if the browser should resend data |
onLoadResource
public void onLoadResource (WebView view, String url)
Notify the host application that the WebView will load the resource specified by the given url.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| url | String: The url of the resource the WebView will load. |
onPageCommitVisible
public void onPageCommitVisible (WebView view, String url)
Notify the host application that [WebView](/reference/android/webkit/WebView) content left over from previous page navigations will no longer be drawn.
This callback can be used to determine the point at which it is safe to make a recycled[WebView](/reference/android/webkit/WebView) visible, ensuring that no stale content is shown. It is called at the earliest point at which it can be guaranteed that [WebView.onDraw](/reference/android/webkit/WebView#onDraw%28android.graphics.Canvas%29) will no longer draw any content from previous navigations. The next draw will display either the[background color](/reference/android/webkit/WebView#setBackgroundColor%28int%29) of the [WebView](/reference/android/webkit/WebView), or some of the contents of the newly loaded page.
This method is called when the body of the HTTP response has started loading, is reflected in the DOM, and will be visible in subsequent draws. This callback occurs early in the document loading process, and as such you should expect that linked resources (for example, CSS and images) may not be available.
For more fine-grained notification of visual state updates, see [WebView.postVisualStateCallback](/reference/android/webkit/WebView#postVisualStateCallback%28long,%20android.webkit.WebView.VisualStateCallback%29).
Please note that all the conditions and recommendations applicable to[WebView.postVisualStateCallback](/reference/android/webkit/WebView#postVisualStateCallback%28long,%20android.webkit.WebView.VisualStateCallback%29) also apply to this API.
This callback is only called for main frame navigations.
| Parameters | |
|---|---|
| view | WebView: The WebView for which the navigation occurred. |
| url | String: The URL corresponding to the page navigation that triggered this callback. |
onPageFinished
public void onPageFinished (WebView view, String url)
Notify the host application that a page has finished loading. This method is called only for main frame. Receiving an onPageFinished() callback does not guarantee that the next frame drawn by WebView will reflect the state of the DOM at this point. In order to be notified that the current DOM state is ready to be rendered, request a visual state callback with [WebView.postVisualStateCallback](/reference/android/webkit/WebView#postVisualStateCallback%28long,%20android.webkit.WebView.VisualStateCallback%29) and wait for the supplied callback to be triggered.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| url | String: The url of the page. |
onPageStarted
public void onPageStarted (WebView view, String url, Bitmap favicon)
Notify the host application that a page has started loading. This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted one time for the main frame. This also means that onPageStarted will not be called when the contents of an embedded frame changes, i.e. clicking a link whose target is an iframe, it will also not be called for fragment navigations (navigations to #fragment_id).
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| url | String: The url to be loaded. |
| favicon | Bitmap: The favicon for this page if it already exists in the database. |
onReceivedClientCertRequest
public void onReceivedClientCertRequest (WebView view, ClientCertRequest request)
Notify the host application to handle a SSL client certificate request. The host application is responsible for showing the UI if desired and providing the keys. There are three ways to respond: [ClientCertRequest.proceed](/reference/android/webkit/ClientCertRequest#proceed%28java.security.PrivateKey,%20java.security.cert.X509Certificate[]%29), [ClientCertRequest.cancel](/reference/android/webkit/ClientCertRequest#cancel%28%29), or [ClientCertRequest.ignore](/reference/android/webkit/ClientCertRequest#ignore%28%29). Webview stores the response in memory (for the life of the application) if [ClientCertRequest.proceed](/reference/android/webkit/ClientCertRequest#proceed%28java.security.PrivateKey,%20java.security.cert.X509Certificate[]%29) or [ClientCertRequest.cancel](/reference/android/webkit/ClientCertRequest#cancel%28%29) is called and does not call onReceivedClientCertRequest() again for the same host and port pair. Webview does not store the response if [ClientCertRequest.ignore](/reference/android/webkit/ClientCertRequest#ignore%28%29) is called. Note that, multiple layers in chromium network stack might be caching the responses, so the behavior for ignore is only a best case effort. This method is called on the UI thread. During the callback, the connection is suspended. For most use cases, the application program should implement the[KeyChainAliasCallback](/reference/android/security/KeyChainAliasCallback) interface and pass it to[KeyChain.choosePrivateKeyAlias(Activity, KeyChainAliasCallback, String, Principal, Uri, String)](/reference/android/security/KeyChain#choosePrivateKeyAlias%28android.app.Activity,%20android.security.KeyChainAliasCallback,%20java.lang.String[],%20java.security.Principal[],%20android.net.Uri,%20java.lang.String%29) to start an activity for the user to choose the proper alias. The keychain activity will provide the alias through the callback method in the implemented interface. Next the application should create an async task to call[KeyChain.getPrivateKey(Context, String)](/reference/android/security/KeyChain#getPrivateKey%28android.content.Context,%20java.lang.String%29) to receive the key. An example implementation of client certificates can be seen at AOSP Browser The default behavior is to cancel, returning no client certificate.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback |
| request | ClientCertRequest: An instance of a ClientCertRequest |
onReceivedError
public void onReceivedError (WebView view, int errorCode, String description, String failingUrl)
This method was deprecated in API level 23.
Use [onReceivedError(WebView, WebResourceRequest, WebResourceError)](/reference/android/webkit/WebViewClient#onReceivedError%28android.webkit.WebView,%20android.webkit.WebResourceRequest,%20android.webkit.WebResourceError%29) on [Build.VERSION_CODES.M](/reference/android/os/Build.VERSION%5FCODES#M) and above.
Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable). The errorCode parameter corresponds to one of the ERROR_* constants.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| errorCode | int: The error code corresponding to an ERROR_* value. |
| description | String: A String describing the error. |
| failingUrl | String: The url that failed to load. |
onReceivedError
public void onReceivedError (WebView view, WebResourceRequest request, WebResourceError error)
Report web resource loading error to the host application. These errors usually indicate inability to connect to the server. Note that unlike the deprecated version of the callback, the new version will be called for any resource (iframe, image, etc.), not just for the main page. Thus, it is recommended to perform minimum required work in this callback.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| request | WebResourceRequest: The originating request. |
| error | WebResourceError: Information about the error occurred. |
onReceivedHttpAuthRequest
public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm)
Notifies the host application that the WebView received an HTTP authentication request. The host application can use the supplied[HttpAuthHandler](/reference/android/webkit/HttpAuthHandler) to set the WebView's response to the request. The default behavior is to cancel the request.
Note: The supplied HttpAuthHandler must be used on the UI thread.
| Parameters | |
|---|---|
| view | WebView: the WebView that is initiating the callback |
| handler | HttpAuthHandler: the HttpAuthHandler used to set the WebView's response |
| host | String: the host requiring authentication |
| realm | String: the realm for which authentication is required |
onReceivedHttpError
public void onReceivedHttpError (WebView view, WebResourceRequest request, WebResourceResponse errorResponse)
Notify the host application that an HTTP error has been received from the server while loading a resource. HTTP errors have status codes >= 400. This callback will be called for any resource (iframe, image, etc.), not just for the main page. Thus, it is recommended to perform minimum required work in this callback. Note that the content of the server response may not be provided within the errorResponse parameter.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| request | WebResourceRequest: The originating request. |
| errorResponse | WebResourceResponse: Information about the error occurred. |
onReceivedLoginRequest
public void onReceivedLoginRequest (WebView view, String realm, String account, String args)
Notify the host application that a request to automatically log in the user has been processed.
| Parameters | |
|---|---|
| view | WebView: The WebView requesting the login. |
| realm | String: The account realm used to look up accounts. |
| account | String: An optional account. If not null, the account should be checked against accounts on the device. If it is a valid account, it should be used to log in the user. |
| args | String: Authenticator specific arguments used to log in the user. |
onReceivedSslError
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error)
Notifies the host application that an SSL error occurred while loading a resource. The host application must call either[SslErrorHandler.cancel()](/reference/android/webkit/SslErrorHandler#cancel%28%29) or [SslErrorHandler.proceed()](/reference/android/webkit/SslErrorHandler#proceed%28%29).
Warning: Application overrides of this method can be used to display custom error pages or to silently log issues, but the host application should always call SslErrorHandler#cancel() and never proceed past errors.
Note: Do not prompt the user about SSL errors. Users are unlikely to be able to make an informed security decision, andWebView does not provide a UI for showing the details of the error in a meaningful way.
The decision to call proceed() or cancel() may be retained to facilitate responses to future SSL errors. The default behavior is to cancel the resource loading process.
This API is called only for recoverable SSL certificate errors. For non-recoverable errors (such as when the server fails the client), theWebView calls [onReceivedError(WebView, WebResourceRequest, WebResourceError)](/reference/android/webkit/WebViewClient#onReceivedError%28android.webkit.WebView,%20android.webkit.WebResourceRequest,%20android.webkit.WebResourceError%29) with the[ERROR_FAILED_SSL_HANDSHAKE](/reference/android/webkit/WebViewClient#ERROR%5FFAILED%5FSSL%5FHANDSHAKE) argument.
| Parameters | |
|---|---|
| view | WebView: WebView that initiated the callback. |
| handler | SslErrorHandler: SslErrorHandler that handles the user's response. |
| error | SslError: SSL error object. |
onRenderProcessGone
public boolean onRenderProcessGone (WebView view, RenderProcessGoneDetail detail)
Notify host application that the given WebView's render process has exited. Multiple WebView instances may be associated with a single render process; onRenderProcessGone will be called for each WebView that was affected. The application's implementation of this callback should only attempt to clean up the specific WebView given as a parameter, and should not assume that other WebView instances are affected. The given WebView can't be used, and should be removed from the view hierarchy, all references to it should be cleaned up, e.g any references in the Activity or other classes saved using [View.findViewById(int)](/reference/android/view/View#findViewById%28int%29) and similar calls, etc. To cause an render process crash for test purpose, the application can call loadUrl("chrome://crash") on the WebView. Note that multiple WebView instances may be affected if they share a render process, not just the specific WebView which loaded chrome://crash.
| Parameters | |
|---|---|
| view | WebView: The WebView which needs to be cleaned up. |
| detail | RenderProcessGoneDetail: the reason why it exited. |
| Returns | |
|---|---|
| boolean | true if the host application handled the situation that process has exited, otherwise, application will crash if render process crashed, or be killed if render process was killed by the system. |
onScaleChanged
public void onScaleChanged (WebView view, float oldScale, float newScale)
Notify the host application that the scale applied to the WebView has changed.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| oldScale | float: The old scale factor |
| newScale | float: The new scale factor |
onTooManyRedirects
public void onTooManyRedirects (WebView view, Message cancelMsg, Message continueMsg)
This method was deprecated in API level 15.
This method is no longer called. When the WebView encounters a redirect loop, it will cancel the load.
Notify the host application that there have been an excessive number of HTTP redirects. As the host application if it would like to continue trying to load the resource. The default behavior is to send the cancel message.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| cancelMsg | Message: The message to send if the host wants to cancel |
| continueMsg | Message: The message to send if the host wants to continue |
onUnhandledKeyEvent
public void onUnhandledKeyEvent (WebView view, KeyEvent event)
Notify the host application that a key was not handled by the WebView. Except system keys, WebView always consumes the keys in the normal flow or if [shouldOverrideKeyEvent(WebView, KeyEvent)](/reference/android/webkit/WebViewClient#shouldOverrideKeyEvent%28android.webkit.WebView,%20android.view.KeyEvent%29) returns true. This is called asynchronously from where the key is dispatched. It gives the host application a chance to handle the unhandled key events.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| event | KeyEvent: The key event. |
shouldInterceptRequest
public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request)
Notify the host application of a resource request and allow the application to return the data. If the return value is null, the WebView will continue to load the resource as usual. Otherwise, the return response and data will be used.
This callback is invoked for a variety of URL schemes (e.g., http(s):, data:, file:, etc.), not only those schemes which send requests over the network. This is not called for javascript: URLs, blob: URLs, or for assets accessed via file:///android_asset/ or file:///android_res/ URLs.
In the case of redirects, this is only called for the initial resource URL, not any subsequent redirect URLs.
Note: This method is called on a thread other than the UI thread so clients should exercise caution when accessing private data or the view system.
Note: When Safe Browsing is enabled, these URLs still undergo Safe Browsing checks. If this is undesired, you can use [WebView.setSafeBrowsingWhitelist](/reference/android/webkit/WebView#setSafeBrowsingWhitelist%28java.util.List<java.lang.String>,%20android.webkit.ValueCallback<java.lang.Boolean>%29) to skip Safe Browsing checks for that host or dismiss the warning in [onSafeBrowsingHit(WebView, WebResourceRequest, int, SafeBrowsingResponse)](/reference/android/webkit/WebViewClient#onSafeBrowsingHit%28android.webkit.WebView,%20android.webkit.WebResourceRequest,%20int,%20android.webkit.SafeBrowsingResponse%29) by calling [SafeBrowsingResponse.proceed](/reference/android/webkit/SafeBrowsingResponse#proceed%28boolean%29).
| Parameters | |
|---|---|
| view | WebView: The WebView that is requesting the resource. |
| request | WebResourceRequest: Object containing the details of the request. |
| Returns | |
|---|---|
| WebResourceResponse | A WebResourceResponse containing the response information or null if the WebView should load the resource itself. |
shouldInterceptRequest
public WebResourceResponse shouldInterceptRequest (WebView view, String url)
This method was deprecated in API level 21.
Use [shouldInterceptRequest(WebView, WebResourceRequest)](/reference/android/webkit/WebViewClient#shouldInterceptRequest%28android.webkit.WebView,%20android.webkit.WebResourceRequest%29) on [Build.VERSION_CODES.M](/reference/android/os/Build.VERSION%5FCODES#M) and above.
Notify the host application of a resource request and allow the application to return the data. If the return value is null, the WebView will continue to load the resource as usual. Otherwise, the return response and data will be used.
This callback is invoked for a variety of URL schemes (e.g., http(s):, data:, file:, etc.), not only those schemes which send requests over the network. This is not called for javascript: URLs, blob: URLs, or for assets accessed via file:///android_asset/ or file:///android_res/ URLs.
In the case of redirects, this is only called for the initial resource URL, not any subsequent redirect URLs.
Note: This method is called on a thread other than the UI thread so clients should exercise caution when accessing private data or the view system.
Note: When Safe Browsing is enabled, these URLs still undergo Safe Browsing checks. If this is undesired, you can use [WebView.setSafeBrowsingWhitelist](/reference/android/webkit/WebView#setSafeBrowsingWhitelist%28java.util.List<java.lang.String>,%20android.webkit.ValueCallback<java.lang.Boolean>%29) to skip Safe Browsing checks for that host or dismiss the warning in [onSafeBrowsingHit(WebView, WebResourceRequest, int, SafeBrowsingResponse)](/reference/android/webkit/WebViewClient#onSafeBrowsingHit%28android.webkit.WebView,%20android.webkit.WebResourceRequest,%20int,%20android.webkit.SafeBrowsingResponse%29) by calling [SafeBrowsingResponse.proceed](/reference/android/webkit/SafeBrowsingResponse#proceed%28boolean%29).
| Parameters | |
|---|---|
| view | WebView: The WebView that is requesting the resource. |
| url | String: The raw url of the resource. |
| Returns | |
|---|---|
| WebResourceResponse | A WebResourceResponse containing the response information or null if the WebView should load the resource itself. |
shouldOverrideKeyEvent
public boolean shouldOverrideKeyEvent (WebView view, KeyEvent event)
Give the host application a chance to handle the key event synchronously. e.g. menu shortcut key events need to be filtered this way. If return true, WebView will not handle the key event. If return false, WebView will always handle the key event, so none of the super in the view chain will see the key event. The default behavior returns false.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| event | KeyEvent: The key event. |
| Returns | |
|---|---|
| boolean | true if the host application wants to handle the key event itself, otherwise return false |
shouldOverrideUrlLoading
public boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request)
Give the host application a chance to take control when a URL is about to be loaded in the current WebView. If a WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the URL. If a WebViewClient is provided, returningtrue causes the current WebView to abort loading the URL, while returningfalse causes the WebView to continue loading the URL as usual.
This callback is not called for all page navigations. In particular, this is not called for navigations which the app initiated with loadUrl(): this callback would not serve a purpose in this case, because the app already knows about the navigation. This callback lets the app know about navigations initiated by the web page (such as navigations initiated by JavaScript code), by the user (such as when the user taps on a link), or by an HTTP redirect (ex. if loadUrl("foo.com") redirects to "bar.com" because of HTTP 301).
Note: Do not call [WebView.loadUrl(String)](/reference/android/webkit/WebView#loadUrl%28java.lang.String%29) with the request's URL and then return true. This unnecessarily cancels the current load and starts a new load with the same URL. The correct way to continue loading a given URL is to simply return false, without calling [WebView.loadUrl(String)](/reference/android/webkit/WebView#loadUrl%28java.lang.String%29).
Note: This method is not called for POST requests.
Note: This method may be called for subframes and with non-HTTP(S) schemes; calling [WebView.loadUrl(String)](/reference/android/webkit/WebView#loadUrl%28java.lang.String%29) with such a URL will fail.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| request | WebResourceRequest: Object containing the details of the request. |
| Returns | |
|---|---|
| boolean | true to cancel the current load, otherwise return false. |
shouldOverrideUrlLoading
public boolean shouldOverrideUrlLoading (WebView view, String url)
This method was deprecated in API level 24.
Use [shouldOverrideUrlLoading(WebView, WebResourceRequest)](/reference/android/webkit/WebViewClient#shouldOverrideUrlLoading%28android.webkit.WebView,%20android.webkit.WebResourceRequest%29) on [Build.VERSION_CODES.N](/reference/android/os/Build.VERSION%5FCODES#N) and above.
Give the host application a chance to take control when a URL is about to be loaded in the current WebView. If a WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the URL. If a WebViewClient is provided, returningtrue causes the current WebView to abort loading the URL, while returningfalse causes the WebView to continue loading the URL as usual.
Note: Do not call [WebView.loadUrl(String)](/reference/android/webkit/WebView#loadUrl%28java.lang.String%29) with the same URL and then return true. This unnecessarily cancels the current load and starts a new load with the same URL. The correct way to continue loading a given URL is to simply return false, without calling [WebView.loadUrl(String)](/reference/android/webkit/WebView#loadUrl%28java.lang.String%29).
Note: This method is not called for POST requests.
Note: This method may be called for subframes and with non-HTTP(S) schemes; calling [WebView.loadUrl(String)](/reference/android/webkit/WebView#loadUrl%28java.lang.String%29) with such a URL will fail.
| Parameters | |
|---|---|
| view | WebView: The WebView that is initiating the callback. |
| url | String: The URL to be loaded. |
| Returns | |
|---|---|
| boolean | true to cancel the current load, otherwise return false. |