WebChromeClient
  public
  
  
  
  class
  WebChromeClient
  
    extends Object
  
  
  
  
  
  
| java.lang.Object | |
| ↳ | android.webkit.WebChromeClient | 
Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        interface | WebChromeClient.CustomViewCallbackA callback interface used by the host application to notify the current page that its custom view has been dismissed. | 
| 
        
        
        
        
        class | WebChromeClient.FileChooserParamsParameters used in the  | 
| Public constructors | |
|---|---|
| 
      WebChromeClient()
       | |
| Public methods | |
|---|---|
| 
        
        
        
        
        
        Bitmap | 
      getDefaultVideoPoster()
      When not playing, video elements are represented by a 'poster' image. | 
| 
        
        
        
        
        
        View | 
      getVideoLoadingProgressView()
      Obtains a View to be displayed while buffering of full screen video is taking place. | 
| 
        
        
        
        
        
        void | 
      getVisitedHistory(ValueCallback<String[]> callback)
      Obtains a list of all visited history items, used for link coloring | 
| 
        
        
        
        
        
        void | 
      onCloseWindow(WebView window)
      Notify the host application to close the given WebView and remove it from the view system if necessary. | 
| 
        
        
        
        
        
        boolean | 
      onConsoleMessage(ConsoleMessage consoleMessage)
      Report a JavaScript console message to the host application. | 
| 
        
        
        
        
        
        void | 
      onConsoleMessage(String message, int lineNumber, String sourceID)
      
      This method was deprecated
      in API level 15.
    Use  | 
| 
        
        
        
        
        
        boolean | 
      onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg)
      Request the host application to create a new window. | 
| 
        
        
        
        
        
        void | 
      onExceededDatabaseQuota(String url, String databaseIdentifier, long quota, long estimatedDatabaseSize, long totalQuota, WebStorage.QuotaUpdater quotaUpdater)
      This method was deprecated in API level 19. This method is no longer called; WebView now uses the HTML5 / JavaScript Quota Management API. | 
| 
        
        
        
        
        
        void | 
      onGeolocationPermissionsHidePrompt()
      Notify the host application that a request for Geolocation permissions,
 made with a previous call to
  | 
| 
        
        
        
        
        
        void | 
      onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback)
      Notify the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin. | 
| 
        
        
        
        
        
        void | 
      onHideCustomView()
      Notify the host application that the current page has exited full screen mode. | 
| 
        
        
        
        
        
        boolean | 
      onJsAlert(WebView view, String url, String message, JsResult result)
      Notify the host application that the web page wants to display a
 JavaScript  | 
| 
        
        
        
        
        
        boolean | 
      onJsBeforeUnload(WebView view, String url, String message, JsResult result)
      Notify the host application that the web page wants to confirm navigation
 from JavaScript  | 
| 
        
        
        
        
        
        boolean | 
      onJsConfirm(WebView view, String url, String message, JsResult result)
      Notify the host application that the web page wants to display a
 JavaScript  | 
| 
        
        
        
        
        
        boolean | 
      onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result)
      Notify the host application that the web page wants to display a
 JavaScript  | 
| 
        
        
        
        
        
        boolean | 
      onJsTimeout()
      This method was deprecated in API level 17. This method is no longer supported and will not be invoked. | 
| 
        
        
        
        
        
        void | 
      onPermissionRequest(PermissionRequest request)
      Notify the host application that web content is requesting permission to access the specified resources and the permission currently isn't granted or denied. | 
| 
        
        
        
        
        
        void | 
      onPermissionRequestCanceled(PermissionRequest request)
      Notify the host application that the given permission request has been canceled. | 
| 
        
        
        
        
        
        void | 
      onProgressChanged(WebView view, int newProgress)
      Tell the host application the current progress of loading a page. | 
| 
        
        
        
        
        
        void | 
      onReceivedIcon(WebView view, Bitmap icon)
      Notify the host application of a new favicon for the current page. | 
| 
        
        
        
        
        
        void | 
      onReceivedTitle(WebView view, String title)
      Notify the host application of a change in the document title. | 
| 
        
        
        
        
        
        void | 
      onReceivedTouchIconUrl(WebView view, String url, boolean precomposed)
      Notify the host application of the url for an apple-touch-icon. | 
| 
        
        
        
        
        
        void | 
      onRequestFocus(WebView view)
      Request display and focus for this WebView. | 
| 
        
        
        
        
        
        void | 
      onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback)
      This method was deprecated in API level 18. This method supports the obsolete plugin mechanism, and will not be invoked in future | 
| 
        
        
        
        
        
        void | 
      onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
      Notify the host application that the current page has entered full screen mode. | 
| 
        
        
        
        
        
        boolean | 
      onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
      Asks the client app to show a file chooser. | 
| Inherited methods | |
|---|---|
Public constructors
WebChromeClient
public WebChromeClient ()
Public methods
getDefaultVideoPoster
public Bitmap getDefaultVideoPoster ()
When not playing, video elements are represented by a 'poster' image. The image to use can be specified by the poster attribute of the video tag in HTML. If the attribute is absent, then a default poster will be used. This method allows the ChromeClient to provide that default image.
| Returns | |
|---|---|
| Bitmap | Bitmap The image to use as a default poster, or nullif no such image is
 available. | 
getVideoLoadingProgressView
public View getVideoLoadingProgressView ()
Obtains a View to be displayed while buffering of full screen video is taking place. The host application can override this method to provide a View containing a spinner or similar.
| Returns | |
|---|---|
| View | View The View to be displayed whilst the video is loading.
 This value may be null. | 
getVisitedHistory
public void getVisitedHistory (ValueCallback<String[]> callback)
Obtains a list of all visited history items, used for link coloring
| Parameters | |
|---|---|
| callback | ValueCallback | 
onCloseWindow
public void onCloseWindow (WebView window)
Notify the host application to close the given WebView and remove it from the view system if necessary. At this point, WebCore has stopped any loading in this window and has removed any cross-scripting ability in javascript.
 As with onCreateWindow(WebView, boolean, boolean, Message), the application should ensure that any
 URL or security indicator displayed is updated so that the user can tell
 that the page they were interacting with has been closed.
| Parameters | |
|---|---|
| window | WebView: The WebView that needs to be closed. | 
onConsoleMessage
public boolean onConsoleMessage (ConsoleMessage consoleMessage)
Report a JavaScript console message to the host application. The ChromeClient should override this to process the log message as they see fit.
| Parameters | |
|---|---|
| consoleMessage | ConsoleMessage: Object containing details of the console message. | 
| Returns | |
|---|---|
| boolean | trueif the message is handled by the client. | 
onConsoleMessage
public void onConsoleMessage (String message, int lineNumber, String sourceID)
      This method was deprecated
      in API level 15.
    Use onConsoleMessage(ConsoleMessage)
      instead.
  
Report a JavaScript error message to the host application. The ChromeClient should override this to process the log message as they see fit.
| Parameters | |
|---|---|
| message | String: The error message to report. | 
| lineNumber | int: The line number of the error. | 
| sourceID | String: The name of the source file that caused the error. | 
onCreateWindow
public boolean onCreateWindow (WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg)
Request the host application to create a new window. If the host
 application chooses to honor this request, it should return true from
 this method, create a new WebView to host the window, insert it into the
 View system and send the supplied resultMsg message to its target with
 the new WebView as an argument. If the host application chooses not to
 honor the request, it should return false from this method. The default
 implementation of this method does nothing and hence returns false.
 
 Applications should typically not allow windows to be created when the
 isUserGesture flag is false, as this may be an unwanted popup.
 
Applications should be careful how they display the new window: don't simply overlay it over the existing WebView as this may mislead the user about which site they are viewing. If your application displays the URL of the main page, make sure to also display the URL of the new window in a similar fashion. If your application does not display URLs, consider disallowing the creation of new windows entirely.
Note: There is no trustworthy way to tell which page requested the new window: the request might originate from a third-party iframe inside the WebView.
| Parameters | |
|---|---|
| view | WebView: The WebView from which the request for a new window
             originated. | 
| isDialog | boolean:trueif the new window should be a dialog, rather than
                 a full-size window. | 
| isUserGesture | boolean:trueif the request was initiated by a user gesture,
                      such as the user clicking a link. | 
| resultMsg | Message: The message to send when once a new WebView has been
                  created. resultMsg.obj is aWebView.WebViewTransportobject. This should be
                  used to transport the new WebView, by callingWebView.WebViewTransport.setWebView(WebView). | 
| Returns | |
|---|---|
| boolean | This method should return trueif the host application will
         create a new window, in which case resultMsg should be sent to
         its target. Otherwise, this method should returnfalse. Returningfalsefrom this method but also sending resultMsg will result in
         undefined behavior. | 
onExceededDatabaseQuota
public void onExceededDatabaseQuota (String url, String databaseIdentifier, long quota, long estimatedDatabaseSize, long totalQuota, WebStorage.QuotaUpdater quotaUpdater)
      This method was deprecated
      in API level 19.
    This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
             Management API.
  
Tell the client that the quota has been exceeded for the Web SQL Database
 API for a particular origin and request a new quota. The client must
 respond by invoking the
 updateQuota(long)
 method of the supplied WebStorage.QuotaUpdater instance. The
 minimum value that can be set for the new quota is the current quota. The
 default implementation responds with the current quota, so the quota will
 not be increased.
| Parameters | |
|---|---|
| url | String: The URL of the page that triggered the notification | 
| databaseIdentifier | String: The identifier of the database where the quota
                           was exceeded. | 
| quota | long: The quota for the origin, in bytes | 
| estimatedDatabaseSize | long: The estimated size of the offending
                              database, in bytes | 
| totalQuota | long: The total quota for all origins, in bytes | 
| quotaUpdater | WebStorage.QuotaUpdater: An instance ofWebStorage.QuotaUpdaterwhich
                     must be used to inform the WebView of the new quota. | 
onGeolocationPermissionsHidePrompt
public void onGeolocationPermissionsHidePrompt ()
Notify the host application that a request for Geolocation permissions,
 made with a previous call to
 onGeolocationPermissionsShowPrompt()
 has been canceled. Any related UI should therefore be hidden.
onGeolocationPermissionsShowPrompt
public void onGeolocationPermissionsShowPrompt (String origin, GeolocationPermissions.Callback callback)
Notify the host application that web content from the specified origin
 is attempting to use the Geolocation API, but no permission state is
 currently set for that origin. The host application should invoke the
 specified callback with the desired permission state. See
 GeolocationPermissions for details.
 
Note that for applications targeting Android N and later SDKs
 (API level > Build.VERSION_CODES.M)
 this method is only called for requests originating from secure
 origins such as https. On non-secure origins geolocation requests
 are automatically denied.
| Parameters | |
|---|---|
| origin | String: The origin of the web content attempting to use the
               Geolocation API. | 
| callback | GeolocationPermissions.Callback: The callback to use to set the permission state for the
                 origin. | 
onHideCustomView
public void onHideCustomView ()
Notify the host application that the current page has exited full screen mode. The host
 application must hide the custom View (the View which was previously passed to onShowCustomView()). After this call, web
 content will render in the original WebView again.
 
Note: if overriding this method, the application must also override
 onShowCustomView().
onJsAlert
public boolean onJsAlert (WebView view, String url, String message, JsResult result)
Notify the host application that the web page wants to display a
 JavaScript alert() dialog.
 
The default behavior if this method returns false or is not
 overridden is to show a dialog containing the alert message and suspend
 JavaScript execution until the dialog is dismissed.
 
To show a custom dialog, the app should return true from this
 method, in which case the default dialog will not be shown and JavaScript
 execution will be suspended. The app should call
 JsResult.confirm() when the custom dialog is dismissed such that
 JavaScript execution can be resumed.
 
To suppress the dialog and allow JavaScript execution to
 continue, call JsResult.confirm() immediately and then return
 true.
 
Note that if the WebChromeClient is set to be null,
 or if WebChromeClient is not set at all, the default dialog will
 be suppressed and Javascript execution will continue immediately.
 
Note that the default dialog does not inherit the Display.FLAG_SECURE flag from the parent window.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| url | String: The url of the page requesting the dialog. | 
| message | String: Message to be displayed in the window. | 
| result | JsResult: A JsResult to confirm that the user closed the window. | 
| Returns | |
|---|---|
| boolean | boolean trueif the request is handled or ignored.falseif WebView needs to show the default dialog. | 
onJsBeforeUnload
public boolean onJsBeforeUnload (WebView view, String url, String message, JsResult result)
Notify the host application that the web page wants to confirm navigation
 from JavaScript onbeforeunload.
 
The default behavior if this method returns false or is not
 overridden is to show a dialog containing the message and suspend
 JavaScript execution until the dialog is dismissed. The default dialog
 will continue the navigation if the user confirms the navigation, and
 will stop the navigation if the user wants to stay on the current page.
 
To show a custom dialog, the app should return true from this
 method, in which case the default dialog will not be shown and JavaScript
 execution will be suspended. When the custom dialog is dismissed, the
 app should call JsResult.confirm() to continue the navigation or,
 JsResult.cancel() to stay on the current page.
 
To suppress the dialog and allow JavaScript execution to continue,
 call JsResult.confirm() or JsResult.cancel() immediately
 and then return true.
 
Note that if the WebChromeClient is set to be null,
 or if WebChromeClient is not set at all, the default dialog will
 be suppressed and the navigation will be resumed immediately.
 
Note that the default dialog does not inherit the Display.FLAG_SECURE flag from the parent window.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| url | String: The url of the page requesting the dialog. | 
| message | String: Message to be displayed in the window. | 
| result | JsResult: A JsResult used to send the user's response to
               javascript. | 
| Returns | |
|---|---|
| boolean | boolean trueif the request is handled or ignored.falseif WebView needs to show the default dialog. | 
onJsConfirm
public boolean onJsConfirm (WebView view, String url, String message, JsResult result)
Notify the host application that the web page wants to display a
 JavaScript confirm() dialog.
 
The default behavior if this method returns false or is not
 overridden is to show a dialog containing the message and suspend
 JavaScript execution until the dialog is dismissed. The default dialog
 will return true to the JavaScript confirm() code when
 the user presses the 'confirm' button, and will return false to
 the JavaScript code when the user presses the 'cancel' button or
 dismisses the dialog.
 
To show a custom dialog, the app should return true from this
 method, in which case the default dialog will not be shown and JavaScript
 execution will be suspended. The app should call
 JsResult.confirm() or JsResult.cancel() when the custom
 dialog is dismissed.
 
To suppress the dialog and allow JavaScript execution to continue,
 call JsResult.confirm() or JsResult.cancel() immediately
 and then return true.
 
Note that if the WebChromeClient is set to be null,
 or if WebChromeClient is not set at all, the default dialog will
 be suppressed and the default value of false will be returned to
 the JavaScript code immediately.
 
Note that the default dialog does not inherit the Display.FLAG_SECURE flag from the parent window.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| url | String: The url of the page requesting the dialog. | 
| message | String: Message to be displayed in the window. | 
| result | JsResult: A JsResult used to send the user's response to
               javascript. | 
| Returns | |
|---|---|
| boolean | boolean trueif the request is handled or ignored.falseif WebView needs to show the default dialog. | 
onJsPrompt
public boolean onJsPrompt (WebView view, String url, String message, String defaultValue, JsPromptResult result)
Notify the host application that the web page wants to display a
 JavaScript prompt() dialog.
 
The default behavior if this method returns false or is not
 overridden is to show a dialog containing the message and suspend
 JavaScript execution until the dialog is dismissed. Once the dialog is
 dismissed, JavaScript prompt() will return the string that the
 user typed in, or null if the user presses the 'cancel' button.
 
To show a custom dialog, the app should return true from this
 method, in which case the default dialog will not be shown and JavaScript
 execution will be suspended. The app should call
 JsPromptResult.confirm(result) when the custom dialog is
 dismissed.
 
To suppress the dialog and allow JavaScript execution to continue,
 call JsPromptResult.confirm(result) immediately and then
 return true.
 
Note that if the WebChromeClient is set to be null,
 or if WebChromeClient is not set at all, the default dialog will
 be suppressed and null will be returned to the JavaScript code
 immediately.
 
Note that the default dialog does not inherit the Display.FLAG_SECURE flag from the parent window.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| url | String: The url of the page requesting the dialog. | 
| message | String: Message to be displayed in the window. | 
| defaultValue | String: The default value displayed in the prompt dialog. | 
| result | JsPromptResult: A JsPromptResult used to send the user's reponse to
               javascript. | 
| Returns | |
|---|---|
| boolean | boolean trueif the request is handled or ignored.falseif WebView needs to show the default dialog. | 
onJsTimeout
public boolean onJsTimeout ()
      This method was deprecated
      in API level 17.
    This method is no longer supported and will not be invoked.
  
Tell the client that a JavaScript execution timeout has occured. And the
 client may decide whether or not to interrupt the execution. If the
 client returns true, the JavaScript will be interrupted. If the client
 returns false, the execution will continue. Note that in the case of
 continuing execution, the timeout counter will be reset, and the callback
 will continue to occur if the script does not finish at the next check
 point.
| Returns | |
|---|---|
| boolean | boolean Whether the JavaScript execution should be interrupted. | 
onPermissionRequest
public void onPermissionRequest (PermissionRequest request)
Notify the host application that web content is requesting permission to
 access the specified resources and the permission currently isn't granted
 or denied. The host application must invoke PermissionRequest.grant(String[])
 or PermissionRequest.deny().
 If this method isn't overridden, the permission is denied.
| Parameters | |
|---|---|
| request | PermissionRequest: the PermissionRequest from current web content. | 
onPermissionRequestCanceled
public void onPermissionRequestCanceled (PermissionRequest request)
Notify the host application that the given permission request has been canceled. Any related UI should therefore be hidden.
| Parameters | |
|---|---|
| request | PermissionRequest: the PermissionRequest that needs be canceled. | 
onProgressChanged
public void onProgressChanged (WebView view, int newProgress)
Tell the host application the current progress of loading a page.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| newProgress | int: Current page loading progress, represented by
                    an integer between 0 and 100. | 
onReceivedIcon
public void onReceivedIcon (WebView view, Bitmap icon)
Notify the host application of a new favicon for the current page.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| icon | Bitmap: A Bitmap containing the favicon for the current page. | 
onReceivedTitle
public void onReceivedTitle (WebView view, String title)
Notify the host application of a change in the document title.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| title | String: A String containing the new title of the document. | 
onReceivedTouchIconUrl
public void onReceivedTouchIconUrl (WebView view, String url, boolean precomposed)
Notify the host application of the url for an apple-touch-icon.
| Parameters | |
|---|---|
| view | WebView: The WebView that initiated the callback. | 
| url | String: The icon url. | 
| precomposed | boolean:trueif the url is for a precomposed touch icon. | 
onRequestFocus
public void onRequestFocus (WebView view)
Request display and focus for this WebView. This may happen due to another WebView opening a link in this WebView and requesting that this WebView be displayed.
| Parameters | |
|---|---|
| view | WebView: The WebView that needs to be focused. | 
onShowCustomView
public void onShowCustomView (View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback)
      This method was deprecated
      in API level 18.
    This method supports the obsolete plugin mechanism,
 and will not be invoked in future
  
Notify the host application that the current page would like to show a custom View in a particular orientation.
| Parameters | |
|---|---|
| view | View: is the View object to be shown. | 
| requestedOrientation | int: An orientation constant as used inActivityInfo.screenOrientation. | 
| callback | WebChromeClient.CustomViewCallback: is the callback to be invoked if and when the view
 is dismissed. | 
onShowCustomView
public void onShowCustomView (View view, WebChromeClient.CustomViewCallback callback)
Notify the host application that the current page has entered full screen mode. After this
 call, web content will no longer be rendered in the WebView, but will instead be rendered
 in view. The host application should add this View to a Window which is configured
 with WindowManager.LayoutParams.FLAG_FULLSCREEN flag in order to
 actually display this web content full screen.
 
The application may explicitly exit fullscreen mode by invoking callback (ex. when
 the user presses the back button). However, this is generally not necessary as the web page
 will often show its own UI to close out of fullscreen. Regardless of how the WebView exits
 fullscreen mode, WebView will invoke onHideCustomView(), signaling for the
 application to remove the custom View.
 
If this method is not overridden, WebView will report to the web page it does not support fullscreen mode and will not honor the web page's request to run in fullscreen mode.
Note: if overriding this method, the application must also override
 onHideCustomView().
| Parameters | |
|---|---|
| view | View: is the View object to be shown. | 
| callback | WebChromeClient.CustomViewCallback: invoke this callback to request the page to exit
 full screen mode. | 
onShowFileChooser
public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
Asks the client app to show a file chooser. The web page has requested to either upload or
 save a file, such as from a 'file' input in an HTML form or due to a JavaScript API call. The
 client app can decide whether to show the user a file chooser dialog or to programmatically
 handle the request. This can be invoked both for uploads and downloads, and it can also be
 invoked for single files, multiple files, or entire folders. Client apps should check fileChooserParams for details about what type of file is being requested.
 
To show the user a file chooser dialog, override this callback to return true and
 store the filePathCallback in a variable. Present the dialog to the user and when
 they reply, invoke the callback with a URI which points to the file. Make sure to check the
 fileChooserParams in order to show appropriate options in the file chooser dialog,
 such as automatically filtering by relevant file type (see WebChromeClient.FileChooserParams.getAcceptTypes()).
 
To handle each request programmatically, respond to this callback with true. You
 can invoke filePathCallback with null in order to cancel the request or you
 can invoke the callback with a URI to actual file or folder.
 
The default behavior is that WebView will cancel all file requests.
Note: WebView does not enforce any restrictions on
 the chosen file(s). WebView can access all files that your app can access.
 In case the file(s) are chosen through an untrusted source such as a third-party
 app, it is your own app's responsibility to check what the returned Uris
 refer to before calling the filePathCallback. See
 FileChooserParams.createIntent and FileChooserParams.parseResult for more
 details.
| Parameters | |
|---|---|
| webView | WebView: The WebView instance that is initiating the request. | 
| filePathCallback | ValueCallback: Invoke this callback to supply the list of paths to files to upload,
                         ornullto cancel. Must only be called if theonShowFileChooser(WebView, ValueCallback, FileChooserParams)implementation returnstrue. | 
| fileChooserParams | WebChromeClient.FileChooserParams: Describes the mode of file chooser to be opened, and options to be
                          used with it. | 
| Returns | |
|---|---|
| boolean | trueif filePathCallback will be invoked,falseto use default
         handling. | 
See also:
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
