B4A Library UltimateWebView Custom View

UltimateWebView

Author:
Ivica Golubovic
Version: 1.5
  • ConsoleMessage
    • Functions:
      • Create (Message As String, SourceID As String, LineNumber As Int, MSGLevel As Object) As String
      • Create2 (JavaConsoleMessage As Object) As String
      • Initialize As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
    • Properties:
      • LineNumber As Int [read only]
      • Message As String [read only]
      • MessageLevel As Object [read only]
      • MessageLevels As MessageLevels [read only]
      • SourceId As String [read only]
  • DownloadProperties
    • Fields:
      • ContentDisposition As String
      • ContentLength As Long
      • Cookies As String
      • DownloadID As Long
      • FileExtension As String
      • FileName As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • MimeType As String
      • Url As String
      • UserAgent As String
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • FileChooserParams
    • Functions:
      • Initialize (JavaFileChooserParams As Object) As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • ParseResult (ResultCode As Int, Data As Intent) As Object
        Parse the result returned by the file picker activity.
    • Properties:
      • AcceptTypes As String() [read only]
        Returns an array of acceptable MIME types.
      • FilenameHint As String [read only]
        The file name of a default selection if specified, or null.
      • Intent As Intent [read only]
        Creates an intent that would start a file picker for file selection.
      • IsCaptureEnabled As Boolean [read only]
        Returns preference for a live media captured value (e.g. Camera, Microphone).
      • Mode As Int [read only]
        Returns file chooser mode.
      • ModeAsString As String [read only]
        Returns string value for file chooser mode.
      • Title As String [read only]
        Returns the title to use for this file selector.
  • FileProvider
    • Fields:
      • SharedFolder As String
      • UseFileProvider As Boolean
    • Functions:
      • GetFileUri (FileName As String) As Object
        Returns the file uri.
      • Initialize As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • SetFileUriAsIntentData (Intent As Intent, FileName As String) As String
        Replaces the intent Data field with the file uri.
        Resets the type field. Make sure to call Intent.SetType after calling this method
  • HttpAuthHandler
    • Functions:
      • Cancel As String
        Instructs the WebView to cancel the authentication request.
      • Initialize (JavaHttpAuthHandler As Object) As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Proceed (Username As String, Password As String) As String
        Instructs the WebView to proceed with the authentication with the given credentials.
      • toObject As Object
        Returns Object as android.webkit.HttpAuthHandler which can be used in Java Code.
      • UseHttpAuthUsernamePassword As Boolean
        Gets whether the credentials stored for the current host
  • HttpAuthRequestProperties
    • Fields:
      • Host As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Realm As String
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • JsProperties
    • Fields:
      • DefaultValue As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Message As String
      • Url As String
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • JsResult
    • Functions:
      • Cancel As String
        Handle the result if the user cancelled the dialog.
      • Confirm As String
        Handle a confirmation response from the user.
      • Initialize (JavaJsResult As Object) As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • toObject As Object
        Returns Object as android.webkit.JsResult which can be used in Java Code.
  • LoginRequestProperties
    • Fields:
      • Account As String
      • Args As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Realm As String
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • MessageLevels
    • Fields:
      • DEBUG As Object
      • ERROR As Object
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • LOG_ As Object
      • TIP As Object
      • WARNING As Object
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • UltimateCookieManager
    • Functions:
      • Flush As String
        Ensures all cookies currently accessible through the getCookie API are written to persistent storage.
      • GetCookie (Url As String) As String
        Gets all the cookies for the given URL.
      • HasCookies As Boolean
        Gets whether there are stored cookies.
      • Initialize (UltimateWebView1 As UltimateWebView) As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • RemoveAllCookies As String
        Removes all cookies.
      • RemoveExpiredCookie As String
        This method was deprecated in API level 21. The WebView handles removing expired cookies automatically.
      • RemoveSessionCookies As String
        Removes all session cookies, which are cookies without an expiration date.
      • SetCookie (Url As String, Value As String) As String
        Sets a single cookie (key-value pair) for the given URL.
    • Properties:
      • AcceptCookies As Boolean
        Gets or sets whether the application's UltimateWebView instances send and accept cookies.
      • AcceptFileSchemeCookies As Boolean
        This method was deprecated in API level 30. This setting is not secure.
      • AcceptThirdPartyCookies As Boolean
        Gets or sets whether the UltimateWebView should allow third party cookies to be set.
  • UltimateMimeTypeMap
    • Functions:
      • ExtensionFromMimeType (MimeType As String) As String
        Return the registered extension for the given MIME type.
      • FileExtensionFromUrl (Url As String) As String
        Returns the file extension or an empty string if there is no extension.
      • HasExtension (Extension As String) As Boolean
        Return true if the given extension has a registered MIME type.
      • HasMimeType (MimeType As String) As Boolean
        Return true if the given MIME type has an entry in the map.
      • Initialize As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • MimeTypeFromExtension (Extension As String) As String
        Return the MIME type for the given extension.
  • UltimateURLUtil
    • Functions:
      • ComposeSearchUrl (InQuery As String, Template As String, QueryPlaceHolder As String) As String
      • Decode (Url As Byte()) As Byte()
      • GuessFileName (Url As String, ContentDisposition As String, MimeType As String) As String
        Guesses canonical filename that a download would have, using the URL and contentDisposition.
      • GuessUrl (InUrl As String) As String
        Cleans up (if possible) user-entered web addresses
      • Initialize As String
        Initializes the object.
      • IsAboutUrl (Url As String) As Boolean
      • IsAssetUrl (Url As String) As Boolean
      • IsContentUrl (Url As String) As Boolean
      • IsDataUrl (Url As String) As Boolean
      • IsFileUrl (Url As String) As Boolean
      • IsHttpsUrl (Url As String) As Boolean
      • IsHttpUrl (Url As String) As Boolean
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • IsJavaScriptUrl (Url As String) As Boolean
      • IsNetworkUrl (Url As String) As Boolean
      • IsValidUrl (Url As String) As Boolean
      • StripAnchor (Url As String) As String
        Strips the url of the anchor.
  • UltimateWebView
    • Events:
      • ConsoleMessage (ConsoleMessage1 As ConsoleMessage) As Boolean
      • ExecuteJavaScriptResult (Result As String)
      • FileChooserInitialized (FilePathCallback As Object, FileChooserParams1 As FileChooserParams)
      • FileDownloadCompleted (Success As Boolean, DownloadProperties1 As DownloadProperties)
      • FileDownloadInitialized (DownloadProperties1 As DownloadProperties)
      • FileDownloadStarted (DownloadProperties1 As DownloadProperties)
      • JsAlert (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean
      • JsBeforeUnload (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean
      • JsConfirm (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean
      • LoadResource (Url As String)
      • OverrideUrl (WebResourceRequest1 As WebResourceRequest) As Boolean
      • OverrideUrlWithExternalAppIntent (WebResourceRequest1 As WebResourceRequest, ExternalAppIntent As Intent) As Boolean
      • PageCommitVisible (Url As String)
      • PageFinished (Url As String)
      • PageLoadingProgressChanged (Progress As Int)
      • PageStarted (Url As String, FavIcon As Bitmap)
      • PermissionRequest (RequestedPermission As String)
      • ReceivedError (WebResourceRequest1 As WebResourceRequest, WebResourceError1 As WebResourceError)
      • ReceivedHttpAuthRequest (HttpAuthHandler1 As HttpAuthHandler, HttpAuthRequestProperties1 As HttpAuthRequestProperties)
      • ReceivedHttpError (WebResponseRequest1 As WebResourceRequest, WebResourceResponse1 As WebResourceResponse)
      • ReceivedIcon (Icon As Bitmap)
      • ReceivedLoginRequest (LoginRequestProperties1 As LoginRequestProperties)
      • ReceivedTitle (Title As String)
      • ScaleChanged (OldScale As Float, NewScale As Float)
      • ShouldInterceptRequest (Request As WebResourceRequest) As WebResourceResponse
      • UpdateVisitedHistory (Url As String, IsReload As Boolean)
    • Functions:
      • AddJavascriptInterface (Javascript As Object, Name As String) As String
        Injects the supplied Java object into this UltimateWebView. The object is injected into all frames of the web page, including all the iframes, using the supplied name. This allows the Java object's methods to be accessed from JavaScript.
      • BringToFront As String
      • CanGoBack As Boolean
        Gets whether this UltimateWebView has a back history item.
      • CanGoBackOrForward (Steps As Int) As Boolean
        Gets whether the page can go back or forward the given number of steps.
        Steps as Int (negative - back or positive - forward number of steps to move the history)
      • CanGoForward As Boolean
        Gets whether this UltimateWebView has a forward history item.
      • CaptureScreenshotToBitmap As Bitmap
        Capture UltimateWebView visible area to Bitmap.
      • CaptureScreenshotToImageFile (FilePath As String, FileNameWithExtension As String, ImageType As String, ImageQuality As Int) As Boolean
        Capture UltimateWebView visible area to Image File.
        Permission WRITE_EXTERNAL_STORAGE required
        ImageType: "jpeg" or "png" or "webp"
        ImageQuality: 1 to 100
      • ClearCache (IncludeDiskFiles As Boolean) As String
        Clears the resource cache. Note that the cache is per-application, so this will clear the cache for all UltimateWebViews used.
        IncludeDiskFiles As Boolean (if false, only the RAM cache is cleared)
      • ClearFormData As String
        Removes the autocomplete popup from the currently focused form field, if present.
      • ClearHistory As String
        Tells this UltimateWebView to clear its internal back/forward list.
      • ClearMatches As String
        Clears the highlighting surrounding text matches created by findAllAsync(String).
      • ClearSslPreferences As String
        Clears the SSL preferences table stored in response to proceeding with SSL certificate errors.
      • ComputeScroll As String
        Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.
      • DesignerCreateView (Base As Panel, Lbl As Label, Props As Map) As String
      • EnableSlowWholeDocumentDraw As String
        For apps targeting the L release, UltimateWebView has a new default behavior that reduces memory footprint and increases performance by intelligently choosing the portion of the HTML document that needs to be drawn. These optimizations are transparent to the developers.
      • ExecuteJavaScript (JavaScript As String) As String
        Execute Javascript in UltimateWebView.
        Important: UltimateWebView1.Settings.JavaScriptEnabled=True 'Must be set to True somewhere in code
      • ExecuteJavaScript2 (JavaScript As String) As String
        Execute Javascript in UltimateWebView and got asynchronius backward Result.
        Event "ExecuteJavaScriptResult (Result as String)" will be fired when result is available. Result can be "null".
        Example:
        UltimateWebView1.Settings.JavaScriptEnabled=True 'Must be set to True somewhere in code
        UltimateWebView1.ExecuteJavascript2([Your JavaScript Code])
        Wait For UltimateWebView1_ExecuteJavaScriptResult (Result As String)
        'Do your stuff with Result
      • FileChooserStart (FilePathCallback As Object, FileChooserParams1 As FileChooserParams, ForceIsCaptureEnabled As Boolean) As String
        You can use this method to run FileChooser to upload a file. It is important that you use this method in the FileChooserInitialized event.
        FilePathCallback and FileChooserParams1 are initialized by Event.
        ForceIsCaptureEnabled As Boolean - True: Use resources such as camera, microphone, etc. by force if the required file format is appropriate. False: Use a predefined value assigned to FileChooserParams.
      • FindAllAsync (Find As String) As String
        Finds all instances of find on the page and highlights them, asynchronously.
      • FindNext (Forward As Boolean) As String
        Highlights and scrolls to the next match found by FindAllAsync(Find As String), wrapping around page boundaries as necessary.
      • FlingScroll (X As Int, Y As Int) As String
      • GoBack As String
        Goes back in the history of this UltimateWebView.
      • GoBackOrForward (Steps As Int) As String
        Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.
      • GoForward As String
        Goes forward in the history of this UltimateWebView.
      • GrantPermission (Granted As Boolean) As String
        Use to grant or deny permissions which is required by loaded WebSite (Camera, Microphone, Geolocation, Externall Storage...).
        Event PermissionRequest (RequestedPermission As String) will be fired when permission is required.
        Use RuntimePermissions library to handle permission request.
        Example:
        Sub UltimateWebView1_PermissionRequest (RequestedPermission As String)
        Dim rp As RuntimePermissions
        rp.CheckAndRequest(RequestedPermission)
        Wait For Activity_PermissionResult (Permission As String, result As Boolean)
        UltimateWebView1.GrantPermission(result)
        End Sub
      • Initialize (Callback As Object, EventName As String) As String
        Method is called automatically when object is added through Designer.
      • Invalidate As String
      • InvokeZoomPicker As String
        Invokes the graphical zoom picker widget for this WebView.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • LoadData (Data As String, MimeType As String, Encoding As String) As String
        Note that JavaScript's same origin policy means that script running in a page loaded using this method will be unable to access content loaded using any scheme other than 'data', including 'http(s)'. To avoid this restriction, use LoadDataWithBaseURL() with an appropriate base URL.
        The encoding parameter specifies whether the data Is base64 Or URL encoded. If the data Is base64 encoded, the value of the encoding parameter must be "base64"
      • LoadDataWithBaseURL (BaseUrl As String, Data As String, MimeType As String, Encoding As String, HistoryUrl As String) As String
        Loads the given data into this UltimateWebView, using baseUrl as the base URL for the content. The base URL is used both to resolve relative URLs and when applying JavaScript's same origin policy. The historyUrl is used for the history entry.
      • LoadFileFromDirAssets (FileName As String) As String
        Loads file (HTML, TXT, PNG, JPG...) from DirAssets folder into UltimateWebView.
      • LoadFileFromDirInternal (FileName As String) As String
        Loads file (HTML, TXT, PNG, JPG...) from DirInternal folder into UltimateWebView.
      • LoadUrl (Url As String) As String
        Loads the given URL.
      • LoadUrl2 (Url As String, AdditionalHttpHeaders As Map) As String
        Loads the given URL with additional HTTP headers, specified as a map from name to value. Note that if this map contains any of the headers that are set by default by this UltimateWebView, such as those controlling caching, accept types or the User-Agent, their values may be overridden by this UltimateWebView's defaults.
      • PageDown (ToBottom As Boolean) As String
        Scrolls the contents of this UltimateWebView down by half the page size.
        ToBottom As Boolean (true to jump to bottom of page).
      • PageUp (ToTop As Boolean) As String
        Scrolls the contents of this UltimateWebView up by half the view size.
        ToTop As Boolean (true to jump to the top of the page).
      • Pause As String
        Does a best-effort attempt to pause any processing that can be paused safely, such as animations and geolocation. Note that this call does not pause JavaScript. To pause JavaScript globally, use pauseTimers().
      • PauseTimers As String
        Pauses all layout, parsing, and JavaScript timers for all UltimateWebViews. This is a global requests, not restricted to just this UltimateWebView. This can be useful if the application has been paused.
      • PostUrl (Url As String, PostData As Byte()) As String
        Loads the URL with postData using "POST" method into this WebView.
      • Reload As String
        Reloads the current URL.
      • RemoveJavascriptInterface (Name As String) As String
        Removes a previously injected Java object from this UltimateWebView. Note that the removal will not be reflected in JavaScript until the page is next (re)loaded.
      • Resume As String
        Resumes a UltimateWebView after a previous call to Pause.
      • ResumeTimers As String
        Resumes all layout, parsing, and JavaScript timers for all UltimateWebViews. This will resume dispatching all timers.
      • SaveWebArchive (Filename As String) As String
        Saves the current view as a web archive.
        Filename As String (the filename where the archive should be placed This value cannot be null).
      • SendToBack As String
      • SetDownloadListener As String
        Set and start Download Listener.
        Events: FileDownloadInitialized (DownloadProperties1 as DownloadProperties)
        Use StartFileDownload method to download file with native Download Manager, or use your own method.
      • SetWebChromeClient As String
        Sets the chrome handler. This is an implementation of WebChromeClient for use in handling JavaScript dialogs, favicons, titles, and the progress.
        Library will initialize WebChromeClient by itself and associate it with UltimateWebView.
        Events associated: JsAlert, JsBeforeUnload, JsConfirm, PermissionRequest, PageLoadingProgressChanged, ReceivedIcon, ReceivedTitle.
        Online file upload option will be enabled by default.
        Geolocation permission will be handled like any other permission request and will trigger PermissionRequest event.
      • SetWebViewClient As String
        Sets the WebViewClient that will receive various notifications and requests.
        Library will initialize WebViewCliect by itself and associate it with UltimateWebView.
        Events associated: LoadResource, OverrideUrl, PageCommitVisible, PageFinished, PageStarted, ReceivedHttpError, ReceivedHttpAuthRequest, ReceivedError, ReceivedLoginRequest, ShouldInterceptRequest, UpdateVisitedHistory.
      • StartFileDownload (DownloadProperties1 As DownloadProperties, DownloadManagerDescription As String, AllowScanningByMediaScanner As Boolean, DownloadManagerNotification As Boolean) As String
        Use this method to download file with native Download Manager.
        Events:
        FileDownloadStarted (DownloadProperties1 As DownloadProperties)
        FileDownloadCompleted (Success As Boolean, DownloadProperties1 As DownloadProperties)
        File will be downloaded in "Download" folder.
      • StopLoading As String
        Stops the current load.
      • ZoomBy (ZoomFactor As Float) As String
        Performs a zoom operation in this UltimateWebView.
        ZoomFactor As Float (the zoom factor to apply. The zoom factor will be clamped to the UltimateWebView's zoom limits. This value must be in the range 0.01 to 100.0 inclusive).
      • ZoomIn As Boolean
        Performs zoom in in this UltimateWebView.
      • ZoomOut As Boolean
        Performs zoom out in this UltimateWebView.
    • Properties:
      • BackgroundColor As Int [write only]
        Sets the background color for this view.
      • Color As Int [write only]
      • Constants As UltimateWebViewConstants [read only]
      • ContentHeight As Int [read only]
        Gets the height in pixels of the HTML content.
      • CookieManager As UltimateCookieManager
        Gets or sets UltimateCookieManager methods and properties. Class is auto initialized.
      • CopyBackForwardList As WebBackForwardList [read only]
      • DataDirectorySuffix As String [write only]
        Define the directory used to store WebView data for the current process.
      • Enabled As Boolean
      • FavIcon As Bitmap [read only]
        Gets the favicon for the current page.
      • Height As Int
      • InitialScale As Int [write only]
        Sets the initial scale for this UltimateWebView. 0 means default.
      • IsPrivateBrowsingEnabled As Boolean [read only]
        Gets whether private browsing is enabled in this UltimateWebView.
      • Left As Int
      • MimeTypeMap As UltimateMimeTypeMap
        Gets or sets UltimateMimeTypeMap methods and properties. Class is auto initialized.
      • NetworkAvailable As Boolean [write only]
        Informs WebView of the network state.
      • OnCheckIsTextEditor As Boolean [read only]
        Check whether the called view is a text editor, in which case it would make sense to automatically display a soft input window for it.
      • OriginalUrl As String [read only]
        Gets the original URL for the current page.
      • OverScrollMode As Int [write only]
        Set the over-scroll mode for this view.
        Values: OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS (allow over-scrolling only if the view content is larger than the container), or OVER_SCROLL_NEVER. Setting the over-scroll mode of a view will have an effect only if the view is capable of scrolling.
      • Padding As Int()
      • Parent As Object [read only]
      • Progress As Int [read only]
        Gets the progress for the current page.
      • ScrollBarStyle As Int [write only]
        Specify the style of the scrollbars.
        Values: For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable, you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding, then you can use SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.
      • Settings As UltimateWebViewSettings
        Gets or sets UltimateWebView Settings. Class is auto initialized.
      • Tag As Object
      • Text As String
      • Title As String [read only]
        Gets the title for the current page.
      • Top As Int
      • Url As String [read only]
        Gets the URL for the current page.
      • URLUtil As UltimateURLUtil
        Gets or sets UltimateURLUtil methods and properties. Class is auto initialized.
      • Visible As Boolean
      • WebView As WebView
        Gets or sets native B4A WebView from or to UltimateWebView.
      • Width As Int
  • UltimateWebViewConstants
    • Fields:
      • CACHEMODE_LOAD_CACHE_ELSE_NETWORK As Int
      • CACHEMODE_LOAD_CACHE_ONLY As Int
      • CACHEMODE_LOAD_DEFAULT As Int
      • CACHEMODE_LOAD_NO_CACHE As Int
      • FORCE_DARK_AUTO As Int
      • FORCE_DARK_OFF As Int
      • FORCE_DARK_ON As Int
      • MENU_ITEM_NONE As Int
      • MENU_ITEM_PROCESS_TEXT As Int
      • MENU_ITEM_SHARE As Int
      • MENU_ITEM_WEB_SEARCH As Int
      • MIXED_CONTENT_ALWAYS_ALLOW As Int
      • MIXED_CONTENT_COMPATIBILITY_MODE As Int
      • MIXED_CONTENT_NEVER_ALLOW As Int
      • OVER_SCROLL_ALWAYS As Int
      • OVER_SCROLL_IF_CONTENT_SCROLLS As Int
      • OVER_SCROLL_NEVER As Int
      • SCROLLBARS_INSIDE_INSET As Int
      • SCROLLBARS_INSIDE_OVERLAY As Int
      • SCROLLBARS_OUTSIDE_INSET As Int
      • SCROLLBARS_OUTSIDE_OVERLAY As Int
    • Functions:
      • Initialize As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
  • UltimateWebViewSettings
    • Functions:
      • Initialize (UltimateWebView1 As UltimateWebView) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
    • Properties:
      • AllowContentAccess As Boolean
        Enables or disables content URL access within WebView.
      • AllowFileAccess As Boolean
        Enables or disables file access within WebView.
      • AllowFileAccessFromFileURLs As Boolean
        This method was deprecated in API level 30. This setting is not secure.
      • AllowUniversalAccessFromFileURLs As Boolean
        This method was deprecated in API level 30. This setting is not secure.
      • AppCacheEnabled As Boolean
        This method was deprecated in API level 30. The Application Cache API is deprecated and this method will become a no-op on all Android versions once support is removed in Chromium. Consider using Service Workers instead. See https://web.dev/appcache-removal/ for more information.
      • AppCacheMaxSize As Long
        This method was deprecated in API level 18. Quota is managed automatically; this method is a no-op.
      • AppCachePath As String
        This method was deprecated in API level 30. The Application Cache API is deprecated and this method will become a no-op on all Android versions once support is removed in Chromium. Consider using Service Workers instead. See https://web.dev/appcache-removal/ for more information.
      • BlockNetworkImage As Boolean
        Sets whether the WebView should not load image resources from the network (resources accessed via http and https URI schemes).
      • BlockNetworkLoads As Boolean
        Sets whether the WebView should not load resources from the network.
      • BuiltInZoomControls As Boolean
        Sets whether the WebView should use its built-in zoom mechanisms.
      • CacheMode As Int
        Overrides the way the cache is used.
        Values (CacheMode_LOAD_DEFAULT=-1, CacheMode_LOAD_CACHE_ELSE_NETWORK=1, CacheMode_LOAD_NO_CACHE=2, CacheMode_LOAD_CACHE_ONLY=3)
      • Constants As UltimateWebViewConstants [read only]
      • CursiveFontFamily As String
        Sets the cursive font family name.
      • DatabaseEnabled As Boolean
        Sets whether the database storage API is enabled.
      • DatabasePath As String
        This method was deprecated in API level 19. Database paths are managed by the implementation and calling this method will have no effect.
      • DefaultFixedFontSize As Int
        Sets the default fixed font size.
      • DefaultFontSize As Int
        Sets the default font size.
      • DefaultTextEncodingName As String
        Sets the default text encoding name to use when decoding html pages.
      • DisabledActionModeMenuItems As Int
        Disables the action mode menu items according to menuItems flag.
        Values (MENU_ITEM_NONE=0, MENU_ITEM_SHARE=1, MENU_ITEM_WEB_SEARCH=2, MENU_ITEM_PROCESS_TEXT=4)
      • DisplayZoomControls As Boolean
        Sets whether the WebView should display on-screen zoom controls when using the built-in zoom mechanisms.
      • DomStorageEnabled As Boolean
        Sets whether the DOM storage API is enabled.
      • EnableSmoothTransition As Boolean
        This method was deprecated in API level 17. This method is now obsolete, and will become a no-op in future.
      • FantasyFontFamily As String
        Sets the fantasy font family name.
      • FixedFontFamily As String
        Sets the fixed font family name.
      • ForceDark As Int
        Set the force dark mode for this WebView.
        Values (FORCE_DARK_OFF=0, FORCE_DARK_AUTO=1, FORCE_DARK_ON=2)
      • GeolocationDatabasePath As String
        This method was deprecated in API level 24. Geolocation database are managed by the implementation and calling this method will have no effect.
      • GeolocationEnabled As Boolean
        Sets whether Geolocation is enabled.
        Permissions in manifest (Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
      • JavaScriptCanOpenWindowsAutomatically As Boolean
        Tells JavaScript to open windows automatically.
      • JavaScriptEnabled As Boolean
        Tells the WebView to enable JavaScript execution.
      • LightTouchEnabled As Boolean
        This method was deprecated in API level 18. From Build.VERSION_CODES.JELLY_BEAN this setting is obsolete and has no effect.
      • LoadsImagesAutomatically As Boolean
        Sets whether the WebView should load image resources.
      • LoadWithOverviewMode As Boolean
        Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width.
      • MediaPlaybackRequiresUserGesture As Boolean
        Sets whether the WebView requires a user gesture to play media.
      • MinimumFontSize As Int
        Sets the minimum font size.
      • MinimumLogicalFontSize As Int
        Sets the minimum logical font size.
      • MixedContentMode As Int
        Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin.
        Values (MIXED_CONTENT_ALWAYS_ALLOW=0, MIXED_CONTENT_NEVER_ALLOW=1, MIXED_CONTENT_COMPATIBILITY_MODE=2).
      • NeedInitialFocus As Boolean
        Tells the WebView whether it needs to set a node to have focus when WebView#requestFocus(int, android.graphics.Rect) is called.
      • OffscreenPreRaster As Boolean
        Sets whether this WebView should raster tiles when it is offscreen but attached to a window.
      • SafeBrowsingEnabled As Boolean
        Sets whether Safe Browsing is enabled.
      • SansSerifFontFamily As String
        Sets the sans-serif font family name.
      • SaveFormData As Boolean
        This method was deprecated in API level 26. In Android O and afterwards, this function does not have any effect, the form data will be saved to platform's autofill service if applicable.
      • SavePassword As Boolean
        This method was deprecated in API level 18. Saving passwords in WebView will not be supported in future versions.
      • SerifFontFamily As String
        Sets the serif font family name.
      • StandardFontFamily As String
        Sets the standard font family name.
      • SupportMultipleWindows As Boolean
        Sets whether the WebView whether supports multiple windows.
      • SupportZoom As Boolean
        Sets whether the WebView should support zooming using its on-screen zoom controls and gestures.
      • TextZoom As Int
        Sets the text zoom of the page in percent.
      • UserAgentString As String
        Sets the WebView's user-agent string.
      • UseWideViewPort As Boolean
        Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport.
  • WebBackForwardList
    • Functions:
      • GetItemAtIndex (Index As Int) As WebHistoryItem
        Get the history item at the given index.
      • Initialize (UltimateWebView1 As UltimateWebView) As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • toList As List
        Convrets object to List Of WebHistoryItem
      • toObject As Object
        Returns Object as android.webkit.WebBackForwardList which can be used in Java Code.
    • Properties:
      • CurrentIndex As Int [read only]
        Get the index of the current history item.
      • CurrentItem As WebHistoryItem [read only]
        Return the current history item.
      • Size As Int [read only]
        Get the total size of the back/forward list.
  • WebHistoryItem
    • Fields:
      • Favicon As Bitmap
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • OriginalUrl As String
      • Title As String
      • Url As String
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • WebResourceError
    • Functions:
      • Initialize (JavaWebResourceError As Object) As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • toObject As Object
        Returns Object as android.webkit.WebResourceError which can be used in Java Code.
    • Properties:
      • Description As String [read only]
        Gets the string describing the error.
      • ErrorCode As Int [read only]
        Gets the error code of the error.
  • WebResourceRequest
    • Functions:
      • Initialize (JavaWebResourceRequest As Object) As String
        Initializes the object.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • toObject As Object
        Returns Object as android.webkit.WebResourceRequest which can be used in Java Code.
    • Properties:
      • GetMethod As String [read only]
        Gets the method associated with the request, for example "GET".
      • GetRequestHeaders As Map [read only]
        Gets the headers associated with the request.
      • GetUrl As String [read only]
        Gets the URL for which the resource request was made.
      • HasGesture As Boolean [read only]
        Gets whether a gesture (such as a click) was associated with the request.
      • IsForMainFrame As Boolean [read only]
        Gets whether the request was made in order to fetch the main frame's document.
      • IsRedirect As Boolean [read only]
        Gets whether the request was a result of a server-side redirect.
  • WebResourceResponse
    • Functions:
      • Create (MimeType As String, Encoding As String, Data As InputStream) As String
        Constructs a resource response with the given MIME type, character encoding, and input stream.
        MimeType As String - the resource response's MIME type, for example "text/html".
        Encoding As String - the resource response's character encoding, for example "utf-8".
        Data As InputStream - the input stream that provides the resource response's data.
      • Create2 (MimeType As String, Encoding As String, StatusCode As Int, ReasonPhrase As String, ResponseHeaders As Map, Data As InputStream) As String
        Constructs a resource response with the given parameters.
        MimeType As String - the resource response's MIME type, for example "text/html".
        Encoding As String - the resource response's character encoding, for example "utf-8".
        StatusCode As Int - the status code needs to be in the ranges [100, 299], [400, 599]. Causing a redirect by specifying a 3xx code is not supported.
        ReasonPhrase As String - the phrase describing the status code, for example "OK". Must be non-empty. This value cannot be null.
        ResponseHeaders As Map - the resource response's headers represented as a mapping of header name -> header value.
        Data As InputStream - the input stream that provides the resource response's data.
      • Create3 (JavaWebResourceResponse As Object) As String
        Constructs a resource from android.webkit.WebResourceResponse generated in Java Code.
      • Initialize As String
        Initializes the object. Empty WebResourceResponse is created.
        Use Create methods to create with parameters.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • StatusCodeAndReasonPhrase (StatusCode As Int, ReasonPharse As String) As String
        Sets the resource response's status code and reason phrase.
        StatusCode As Int - the status code needs to be in the ranges [100, 299], [400, 599]. Causing a redirect by specifying a 3xx code is not supported.
        ReasonPharse As String - the phrase describing the status code, for example "OK". Must be non-empty. This value cannot be Null.
      • toObject As Object
        Returns Object as android.webkit.WebResourceResponse which can be used in Java Code.
    • Properties:
      • Data As InputStream
        Gets or sets the input stream that provides the resource response's data.
      • Encoding As String
        Gets or sets the resource response's encoding.
      • MimeType As String
        Gets or sets the resource response's MIME type.
      • ReasonPhrase As String [read only]
        Gets the description of the resource response's status code.
      • ResponseHeaders As Map
        Gets or sets the headers for the resource response.
      • StatusCode As Int [read only]
        Gets the resource response's status code.


UltimateWebView
Author:
Ivica Golubovic
Version: 1.0

One year ago, I had the opportunity to work on an application that requires a web browser to access a web application created in asp.net. The application was used in a business environment to perform more complex operations. I had a lot of difficulties with all the necessary requirements such as downloading files, webrtc service, geolocation service, uploading files from local memory, uploading files from the camera, using javascripts, etc. I lost a lot of time until I managed to do all the necessary requirements to make BA WebView approximately like other browsers on the market.

To help another less advanced programmer to avoid the problems and difficulties I found myself in, I decided to pack all my work into a library called UltimateWebView.

The purpose of the library is to implement all important classes in one library in order to make work as easy as possible. The library will be upgraded over time by adding new features and protocols.

I packed the library documentation into one zipped file that contains a UltimateWebView_Documentation.zip file. Other attachments are the library itself and BAExample.

For full library functionality, copy the following into the manifest:
Manifest:
'Important
SetApplicationAttribute(android:usesCleartextTraffic,"true")
AddPermission(android.permission.DOWNLOAD_WITHOUT_NOTIFICATION)
'---------------------
'Camera Permissions
AddPermission(android.permission.CAMERA)
AddPermission(android.permission.RECORD_AUDIO)
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddPermission(android.permission.MICROPHONE)
AddPermission("android.hardware.camera")
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'---------------------

'Geolocation Permissions
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
'------------------------

AddManifestText(<uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="18" />
)

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)

UltimateWebView is a Custom View Library and it is possible to add a View through the Designer.

Sample project:
B4AExample:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#BridgeLogger: True

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private txtUrl As EditText
    Private btnGo As Button
    Private UltimateWebView1 As UltimateWebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
 
    UltimateWebView1.SetWebViewClient 'Sets WebViewClient and its Events.
    UltimateWebView1.SetWebChromeClient 'Sets WebChromeClient and its Events.
    'Other UltimateWebViewSettings
    UltimateWebView1.Settings.JavaScriptEnabled=True
    UltimateWebView1.Settings.AllowContentAccess=True
    UltimateWebView1.Settings.AllowFileAccess=True
    UltimateWebView1.Settings.AppCacheEnabled=True
    UltimateWebView1.Settings.CacheMode=UltimateWebView1.Settings.CacheMode_LOAD_DEFAULT
    UltimateWebView1.Settings.JavaScriptCanOpenWindowsAutomatically=True
    UltimateWebView1.Settings.DisplayZoomControls=False
    UltimateWebView1.Settings.DomStorageEnabled=True
    UltimateWebView1.Settings.MediaPlaybackRequiresUserGesture=False
    UltimateWebView1.Settings.AllowFileAccessFromFileURLs=True
    UltimateWebView1.Settings.AllowUniversalAccessFromFileURLs=True
    UltimateWebView1.Settings.GeolocationEnabled=True
    UltimateWebView1.SetDownloadListener 'Sets and start DownloadListener'
 
    'CookieManager Settings to accept all cookies
    UltimateWebView1.CookieManager.AcceptCookies=True
    UltimateWebView1.CookieManager.AcceptThirdPartyCookies=True
    UltimateWebView1.CookieManager.AcceptFileSchemeCookies=True
    UltimateWebView1.CookieManager.Flush
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        ExitApplication
    End If
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode=KeyCodes.KEYCODE_BACK Then
        If UltimateWebView1.CanGoBack=True Then
            UltimateWebView1.GoBack
            Return True
        Else
            Return False
        End If
    Else
        Return False
    End If
End Sub

Sub btnGo_Click
    'You can use LoadUrl2 like in code bellow
    '--------------------------
    'Dim Headerrs As Map
    'Headerrs.Initialize
    'Headerrs.Put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36")
    'UltimateWebView1.LoadUrl2(txtUrl.Text,Headerrs)
    '---------------------------
 
    UltimateWebView1.LoadUrl(txtUrl.Text)
End Sub

Sub UltimateWebView1_FileDownloadInitialized (DownloadProperties1 As DownloadProperties) 'When click to download link or button this event will bi fired.
    Log("Download INITIALIZED")
    'DownloadProperties fields:
    '---------------------------------
    'Log(DownloadProperties1.url)
    'Log(DownloadProperties1.userAgent)
    'Log(DownloadProperties1.contentDisposition)
    'Log(DownloadProperties1.mimeType)
    'Log(DownloadProperties1.contentLength)
    'Log(DownloadProperties1.cookies)
    'Log(DownloadProperties1.fileName)
    'Log(DownloadProperties1.FileExtension)
    'Log(DownloadProperties1.DownloadID)
    '---------------------------------
 
    UltimateWebView1.StartFileDownload(DownloadProperties1,"TEST",True,True) 'File will be downloaded with native DownloadManager. If you want internall download, you can use your own method with parameters from DownloadProperties.
End Sub

Sub UltimateWebView1_FileDownloadStarted (DownloadProperties1 As DownloadProperties)
    Log("Download STARTED")
    'Log(DownloadProperties1.url)
    'Log(DownloadProperties1.userAgent)
    'Log(DownloadProperties1.contentDisposition)
    'Log(DownloadProperties1.mimeType)
    'Log(DownloadProperties1.contentLength)
    'Log(DownloadProperties1.cookies)
    'Log(DownloadProperties1.fileName)
    'Log(DownloadProperties1.FileExtension)
    'Log(DownloadProperties1.DownloadID)
End Sub

Sub UltimateWebView1_FileDownloadCompleted (Success As Boolean, DownloadProperties1 As DownloadProperties)
    Log("Download COMPLETED; Success:" & Success)
    'Log(DownloadProperties1.url)
    'Log(DownloadProperties1.userAgent)
    'Log(DownloadProperties1.contentDisposition)
    'Log(DownloadProperties1.mimeType)
    'Log(DownloadProperties1.contentLength)
    'Log(DownloadProperties1.cookies)
    'Log(DownloadProperties1.fileName)
    'Log(DownloadProperties1.FileExtension)
    'Log(DownloadProperties1.DownloadID)
End Sub

Private Sub UltimateWebView1_OverrideUrl (WebResourceRequest1 As WebResourceRequest) As Boolean
    'Log(WebResourceRequest1.GetUrl)
    'Log(WebResourceRequest1.GetMethod)
    'Log(WebResourceRequest1.HasGesture)
    'Log(WebResourceRequest1.IsForMainFrame)
    'Log(WebResourceRequest1.IsRedirect)
    'Dim M As Map=WebResourceRequest1.GetRequestHeaders
    'If M.IsInitialized Then
        'For i=0 To M.Size-1
            'Log(M.GetKeyAt(i))
            'Log(M.GetValueAt(i))
        'Next
    'End If
    Return False
End Sub

Sub UltimateWebView1_PageFinished (Url As String)
 
End Sub

Sub UltimateWebView1_PageStarted (Url As String, FavIcon As Bitmap)
    'If FavIcon<>Null Then
        'do stuff...
    'End If
End Sub

Sub UltimateWebView1_PageLoadingProgressChanged(Progress As Int)
 
End Sub

Sub UltimateWebView1_ReceivedIcon (Icon As Bitmap)
    'If Icon<>Null Then
    'do stuff...
    'End If
End Sub

Sub UltimateWebView1_ReceivedTitle (Title As String)
 
End Sub

'Very important event for UltimateWebView permissions request!!!
Sub UltimateWebView1_PermissionRequest (RequestedPermission As String)
    Dim Permissions As RuntimePermissions
    Permissions.CheckAndRequest(RequestedPermission)
    Wait For Activity_PermissionResult (Permission As String, result As Boolean)
    UltimateWebView1.GrantPermission(result)
End Sub

Sub UltimateWebView1_ScaleChanged (OldScale As Float, NewScale As Float)
 
End Sub

Private Sub UltimateWebView1_ReceivedError (WebResourceRequest1 As WebResourceRequest, WebResourceError1 As WebResourceError)
    'Log("ReceivedError")
    'Log(WebResourceRequest1.GetUrl)
    'Log(WebResourceError1.Description)
    'Log(WebResourceError1.ErrorCode)
End Sub

Private Sub UltimateWebView1_ReceivedHttpError (WebResponseRequest1 As WebResourceRequest, WebResourceResponse1 As WebResourceResponse)
    'Log("ReceivedHttpError")
    'Log(WebResponseRequest1.GetUrl)
    'Log(WebResourceResponse1.Encoding)
    'Log(WebResourceResponse1.StatusCode)
End Sub

Private Sub UltimateWebView1_ReceivedHttpAuthRequest (HttpAuthHandler1 As HttpAuthHandler, HttpAuthRequestProperties1 As HttpAuthRequestProperties)
    'Log("ReceivedHttpAuthRequest")
    'Log(HttpAuthRequestProperties1.Host)
    'Log(HttpAuthRequestProperties1.Realm)
End Sub

Private Sub UltimateWebView1_ReceivedLoginRequest (LoginRequestProperties1 As LoginRequestProperties)
    'Log("ReceivedLoginRequest")
    'Log(LoginRequestProperties1.Realm)
    'Log(LoginRequestProperties1.Account)
    'Log(LoginRequestProperties1.Args)
End Sub

Private Sub UltimateWebView1_UpdateVisitedHistory (Url As String, IsReload As Boolean)
    'Log("UpdateVisitedHistory")
    'Log(Url)
    'Log(IsReload)
End Sub


Private Sub UltimateWebView1_PageCommitVisible (Url As String)
 
End Sub

Private Sub UltimateWebView1_ShouldInterceptRequest (Request As WebResourceRequest) As WebResourceResponse
    'Log("ShouldInterceptRequest")
    'Log(Request.GetUrl)
    'Dim ins As InputStream
    'ins.InitializeFromBytesArray(Array As Byte(100,231,155),0,3)
    'Dim Response As WebResourceResponse
    'Response.Initialize
    'Response.Create("text/plain","utf-8",ins)
    'Return Response
    Return Null
End Sub


Private Sub UltimateWebView1_JsAlert (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean
    'Log("JsAlert")
    'Log(JsProperties1.Url)
    'Log(JsProperties1.Message)
    'Log(JsProperties1.DefaultValue)
    'JsResult1.Confirm
    Return False
End Sub

Private Sub UltimateWebView1_JsBeforeUnload (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean
    'Log("JsBeforeUnload")
    'Log(JsProperties1.Url)
    'Log(JsProperties1.Message)
    'Log(JsProperties1.DefaultValue)
    'JsResult1.Confirm
    Return False
End Sub

Private Sub UltimateWebView1_JsConfirm (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean
    'Log("JsConfirm")
    'Log(JsProperties1.Url)
    'Log(JsProperties1.Message)
    'Log(JsProperties1.DefaultValue)
    'JsResult1.Confirm
    Return False
End Sub

UltimateWebView
Author:
Ivica Golubovic
Version: 1.1

Changes:
  • Method GetWebView is removed from UltimateWebView Class.
  • Property WebView (get/set) added to UltimateWebView Class. You can now use this property to set existing WebView to UltimateWebView.
  • Added method ClearFormData.
  • Added method ClearMatches.
  • Added method ClearSslPreferences.
  • Added method ComputeScroll.
  • Added class WebBackForwardList.
  • Added type WebHistoryItem to class WebBackForwardList.
  • Added method CopyBackForwardList.
  • Added method FindAllAsync.
  • Added method FindNext.
  • Added method FlingScroll.
You can now import an existing WebView object into UltimateWebView, it is not necessary to add an UltimateWebView object through the Designer.
Example:
Example:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private WebView1 As WebView
    Private UltimateWebView1 As UltimateWebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
 
    'First Initialize UltimateWebView
    UltimateWebView1.Initialize(Me,"UltimateWebView1")
    'Import native WebView into UltimateWebView
    UltimateWebView1.WebView=WebView1
 
    UltimateWebView1.SetWebViewClient
    UltimateWebView1.SetWebChromeClient
    UltimateWebView1.Settings.JavaScriptEnabled=True
    UltimateWebView1.Settings.AllowContentAccess=True
    UltimateWebView1.Settings.AllowFileAccess=True
    UltimateWebView1.Settings.AppCacheEnabled=True
    UltimateWebView1.Settings.CacheMode=UltimateWebView1.Settings.CacheMode_LOAD_DEFAULT
    UltimateWebView1.Settings.JavaScriptCanOpenWindowsAutomatically=True
    UltimateWebView1.Settings.DisplayZoomControls=False
    UltimateWebView1.Settings.DomStorageEnabled=True
    UltimateWebView1.Settings.MediaPlaybackRequiresUserGesture=False
    UltimateWebView1.Settings.AllowFileAccessFromFileURLs=True
    UltimateWebView1.Settings.AllowUniversalAccessFromFileURLs=True
    UltimateWebView1.Settings.GeolocationEnabled=True
    UltimateWebView1.SetDownloadListener
 
    UltimateWebView1.CookieManager.AcceptCookies=True
    UltimateWebView1.CookieManager.AcceptThirdPartyCookies=True
    UltimateWebView1.CookieManager.AcceptFileSchemeCookies=True
    UltimateWebView1.CookieManager.Flush
End Sub

A very important event for the permissions required for WebRTC, Geolocation, etc. Without this event permisions will be denied.
Permission Event:
Sub UltimateWebView1_PermissionRequest (RequestedPermission As String)
    Dim Permissions As RuntimePermissions
    Permissions.CheckAndRequest(RequestedPermission)
    Wait For Activity_PermissionResult (Permission As String, result As Boolean)
    UltimateWebView1.GrantPermission(result)
End Sub

UltimateWebView
Author:
Ivica Golubovic
Version: 1.2

Changes:
  • Added event FileChooserInitialized.
  • Added class FileChooserParams.
  • Added method FileChooserStart.
  • Added automatic permissions requests for UploadFileChooser.
  • Added the ability to upload multiple files with UploadFileChooser if allowed.
  • Added event OverrideUrlWithExternalAppIntent.
FileChooserInitialized event added. It will be activated when a Web source requires uploading a file or multiple files. To start FileChooser, call the FileChooserStart method or use event objects the way you want. Do not add this event if you do not want your application to have this feature.
Example::
Private Sub UltimateWebView1_FileChooserInitialized (FilePathCallback As Object, FileChooserParams1 As FileChooserParams)
    'ForceIsCaptureEnabled As Boolean:
    '    True: Use resources such as camera, microphone, etc. by force if the required file format is appropriate.
    '    False: Use a predefined value assigned to FileChooserParams.
    UltimateWebView1.FileChooserStart(FilePathCallback,FileChooserParams1,True) 'Use this method or use your own method from given parameters
End Sub

Added event OverrideUrlWithExternalAppIntent which will process the request to launch an external application outside of UltimateWebView (e.g. PlayStore, Maps, AppGalery, applies to all installed applications). The result of the event is an Intent which you can use in the way you want (e.g. StartActivity (Intent) - opens the application or application chooser, depending on the case).
Example::
Sub UltimateWebView1_OverrideUrlWithExternalAppIntent (WebResourceRequest1 As WebResourceRequest, ExternalAppIntent As Intent) As Boolean
    'ExternalAppIntent - Intent to use
    StartActivity(ExternalAppIntent) 'You can use this method or do with event what ever you want
    Return True 'True to stop page loading and handling event, False to finish loading page (Error web page will be shown)
End Sub

UltimateWebView
Author:
Ivica Golubovic
Version: 1.3

Changes:
  • Added class UltimateWebViewConstants (All constants required for UltimateWebView and UltimateWebViewSettings have been put into one class for better organization and visibility. They are available through the UltimateWebView.Constants or UltimateWebView.Settings.Constants property.
  • Added method InvokeZoomPicker to UltimateWebView Class .
  • Added method PostUrl to UltimateWebView Class .
  • Added property BackgroundColor to UltimateWebView Class.
  • Added property Constants to UltimateWebView Class.
  • Added property Constants to UltimateWebViewSettings Class.
  • Added property DataDirectorySuffix to UltimateWebView Class.
  • Added property NetworkAvailable to UltimateWebView Class.
  • Added property OverScrollMode to UltimateWebView Class.
  • Added property ScrollBarStyle to UltimateWebView Class.
  • Added property Text to UltimateWebView Class.
  • Fixed event OverrideUrlWithExternalAppIntent. Intent now opens the application directly if is installed.
All constants required for UltimateWebView and UltimateWebViewSettings have been put into one class for better organization and visibility. They are available through the UltimateWebView.Constants or UltimateWebView.Settings.Constants property.
Example::
UltimateWebView1.Settings.CacheMode=UltimateWebView1.Constants.CACHEMODE_LOAD_DEFAULT
Or:
Example::
UltimateWebView1.Settings.CacheMode=UltimateWebView1.Settings.Constants.CACHEMODE_LOAD_DEFAULT


UltimateWebView
Author:
Ivica Golubovic
Version: 1.4

Changes:
  • Added class UltimateMimeTypeMap.
  • Added class UltimateURLUtil.
  • Added property MimeTypeMap to UltimateWebView Class.
  • Added property URLUtil to UltimateWebView Class.

UltimateWebView
Author:
Ivica Golubovic
Version: 1.5

Changes:
  • Added class ConsoleMessage.
  • Added type MessageLevels with predefined values.
  • Added event ConsoleMessage (ConsoleMessage1 As ConsoleMessage) As Boolean.
  • Added method LoadFileFromDirInternal to UltimateWebView Class.
  • Added method LoadFileFromDirAssets to UltimateWebView Class.

Due to the limit on the size of the file that can be uploaded on the forum, from now documentation file is in html format and not pdf.


If this library makes your work easier and saves time in creating your application, please make a donation.
 

Attachments

  • B4AExample.zip
    11.8 KB · Views: 81
  • UltimateWebView_1.5_Doc.zip
    10.8 KB · Views: 41
  • UltimateWebView_1.5_Lib.zip
    72.6 KB · Views: 44
Last edited:

Mashiane

Expert
Licensed User
Q2. Also considering that we have WebViewExtras here in the forum, what is the relation between that and this? Can they work together? There is no need for webview estras when you use this?

Q3. What makes your library the go to library of choice? The documentation assumes that anyone who will use your library will know what they will be doing. In most cases, that is not true. Don't you want to include examples perhaps as part of demonstrating the power of this library, especially the feautures that make this lib outstanding from anything else available? This will help provide some green lights into this baby of yours.

#JustSomeThoughts
 

Ivica Golubovic

Member
Licensed User
One of the most interesting questions that people have asked here is about uploading a file via the webview.?

Is something like that possible with your webview library?
Yes, absolutely. The FileChooserInitialized event will be activated and the FileChooserStart method can be used to start FileChooser automatically. Of course, you can use the event parameters the way you want and do the file upload process in your own way, it is not necessary to use the FileChooserStart method.;)
Example::
Private Sub UltimateWebView1_FileChooserInitialized (FilePathCallback As Object, FileChooserParams1 As FileChooserParams)
    UltimateWebView1.FileChooserStart(FilePathCallback,FileChooserParams1,False)
End Sub

Q2. Also considering that we have WebViewExtras here in the forum, what is the relation between that and this? Can they work together? There is no need for webview estras when you use this?
As of version 1.1, the native WebView can be easily used as UltimateWebWiev (e.g. UltimateWebView1.WebView = WebView1). The same can be implemented WebView which is processed through WebViewExtras. WebViewExtra is an extra library, but it's a bit outdated. The UltimateWebView library is up to date and easy to use on the latest SDK versions. The UltimateWebView library contains almost all (and more) methods contained in the WebViewExtra library and therefore it is not necessary to use both libraries.

Q3. What makes your library the go to library of choice? The documentation assumes that anyone who will use your library will know what they will be doing. In most cases, that is not true. Don't you want to include examples perhaps as part of demonstrating the power of this library, especially the feautures that make this lib outstanding from anything else available? This will help provide some green lights into this baby of yours.
This library is not the final WebBrowser like Chrome, but a set of classes and subroutines that are combined into one whole for easier access. Some programming knowledge is required. Ask a question for all the necessary information.
 
Last edited:

JohnC

Expert
Licensed User
This obviously took a long time to develop - and even more time to create a library and docs for others to use.

THANK YOU for contributing such a useful library to the community!
 

Ivica Golubovic

Member
Licensed User
Version 1.3 released. See first post.

Changes:
  • Added class UltimateWebViewConstants (All constants required for UltimateWebView and UltimateWebViewSettings have been put into one class for better organization and visibility. They are available through the UltimateWebView.Constants or UltimateWebView.Settings.Constants property.
  • Added method InvokeZoomPicker to UltimateWebView Class .
  • Added method PostUrl to UltimateWebView Class .
  • Added property BackgroundColor to UltimateWebView Class.
  • Added property Constants to UltimateWebView Class.
  • Added property Constants to UltimateWebViewSettings Class.
  • Added property DataDirectorySuffix to UltimateWebView Class.
  • Added property NetworkAvailable to UltimateWebView Class.
  • Added property OverScrollMode to UltimateWebView Class.
  • Added property ScrollBarStyle to UltimateWebView Class.
  • Added property Text to UltimateWebView Class.
  • Fixed event OverrideUrlWithExternalAppIntent. Intent now opens the application directly if is installed.
 
Last edited:

Ivica Golubovic

Member
Licensed User
Version 1.4 released. See first post.

Changes:
  • Added class UltimateMimeTypeMap.
  • Added class UltimateURLUtil.
  • Added property MimeTypeMap to UltimateWebView Class.
  • Added property URLUtil to UltimateWebView Class.
 
Last edited:

SAFCO

New Member
Sounds Great...
But how can I load html (As String)? Is it possible? something like this: UltimateWebView.loadHtml
 

Ivica Golubovic

Member
Licensed User
Version 1.5 released. See first post.

Changes:
  • Added class ConsoleMessage.
  • Added type MessageLevels with predefined values.
  • Added event ConsoleMessage (ConsoleMessage1 As ConsoleMessage) As Boolean.
  • Added method LoadFileFromDirInternal to UltimateWebView Class.
  • Added method LoadFileFromDirAssets to UltimateWebView Class.
 

Ivica Golubovic

Member
Licensed User
Make sure to check it in both release and debug modes, as in debug mode the assets folder is a regular folder.
As always, you aim directly at the essence. This is the main reason why this method was added to the library. Since SDK29 and the introduction of Scoped Storage it is not at all possible to load a file directly from DirAssets into WebView (ERR_ACCESS_DENIED or File does not exist). The entire path to the file in DirAssets is just "file: /// AssetsDir / [File Name]" which throws out the error of a non-existent file. I found a solution that I implemented in this method and now it opens the file in Debug and Release mode. Thank you for your cooperation.
 

Ivica Golubovic

Member
Licensed User
Sounds Great...
But how can I load html (As String)? Is it possible? something like this: UltimateWebView.loadHtml
From lib version 1.5:
  • LoadFileFromDirAssets (FileName As String) As String
    Loads file (HTML, TXT, PNG, JPG...) from DirAssets folder into UltimateWebView.
  • LoadFileFromDirInternal (FileName As String) As String
    Loads file (HTML, TXT, PNG, JPG...) from DirInternal folder into UltimateWebView.
From SDK29 and Scoped Storage you can only load HTML file in shared folder. To open file from external you must implement default FileChooser.

Additional information: From SDK30 WebView.Settings.AllowFileAccess is set to FALSE by default. In order for WebView to be able to open any file, you first need to set this option to TRUE.
 
Last edited:

Ivica Golubovic

Member
Licensed User
If anyone has tested the library in any way so far, any feedback is welcome. The goal is to make the library better, more stable, easier to use, to remove bugs. Please report both the pros and cons of this library. CHEERS
 

iz0ndg

Active Member
Licensed User
Hi Ivica, I need to parse the html code and with this
B4X:
        UltimateWebView1.ExecuteJavaScript2("document.documentElement.outerHTML")
        Wait For UltimateWebView1_ExecuteJavaScriptResult(Result As String)
        Log("text " & Result)
I can come up with the result but I don't have the pure html text but somehow encoded like this:

B4X:
"\u003Chtml lang=\"it\">\u003Chead>\n   \u003Cmeta charset=\"utf-8\">\n\n   \u003Cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n   \u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n\n   \u003C!-- Disable tap highlight on IE -->\n

but I would need pure html like this :

HTML:
<html lang="it">
<head>
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

how can I do ?

Tks.
 

Ivica Golubovic

Member
Licensed User
Response from javascript execution is in JSON. You must convert JSON result to html. There is several ways on internet how you can do this in Java. You must use javacode in your B4A project. There is no simple converter.
 

Ivica Golubovic

Member
Licensed User
Hi Ivica, I need to parse the html code and with this
B4X:
        UltimateWebView1.ExecuteJavaScript2("document.documentElement.outerHTML")
        Wait For UltimateWebView1_ExecuteJavaScriptResult(Result As String)
        Log("text " & Result)
I can come up with the result but I don't have the pure html text but somehow encoded like this:

B4X:
"\u003Chtml lang=\"it\">\u003Chead>\n   \u003Cmeta charset=\"utf-8\">\n\n   \u003Cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n   \u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n\n   \u003C!-- Disable tap highlight on IE -->\n

but I would need pure html like this :

HTML:
<html lang="it">
<head>
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

how can I do ?

Tks.
Add this Java code into Activity:
JavaCode::
#If Java
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.lang.StringBuffer;
import java.lang.Integer;

public String jsonToHtml (String data) {
        Pattern p = Pattern.compile("\\\\u(\\p{XDigit}{4})");
        Matcher m = p.matcher(data);
        StringBuffer buf = new StringBuffer(data.length());
        while (m.find()) {
            String ch = String.valueOf((char) Integer.parseInt(m.group(1), 16));
            m.appendReplacement(buf, Matcher.quoteReplacement(ch));
        }
        m.appendTail(buf);
        return buf.toString();
    }

#End If

Add this code in B4A after javascript execution:
BA code::
Dim jo As JavaObject=Me
Dim HtmlResult As String=jo.RunMethod("jsonToHtml",Array(Result))
Log(HtmlResult)
 

iz0ndg

Active Member
Licensed User
Add this Java code into Activity:
JavaCode::
#If Java
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.lang.StringBuffer;
import java.lang.Integer;

public String jsonToHtml (String data) {
        Pattern p = Pattern.compile("\\\\u(\\p{XDigit}{4})");
        Matcher m = p.matcher(data);
        StringBuffer buf = new StringBuffer(data.length());
        while (m.find()) {
            String ch = String.valueOf((char) Integer.parseInt(m.group(1), 16));
            m.appendReplacement(buf, Matcher.quoteReplacement(ch));
        }
        m.appendTail(buf);
        return buf.toString();
    }

#End If

Add this code in B4A after javascript execution:
BA code::
Dim jo As JavaObject=Me
Dim HtmlResult As String=jo.RunMethod("jsonToHtml",Array(Result))
Log(HtmlResult)
Thank you, with some adjustments it was very useful to me !
 
Top