#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