#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 5
#VersionName: 1.4
'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.Settings.JavaScriptEnabled = True
UltimateWebView1.Settings.JavaScriptCanOpenWindowsAutomatically = True
UltimateWebView1.WebChromeClientEnabled=True
UltimateWebView1.Settings.SupportMultipleWindows=True
UltimateWebView1.WebChromeClientEnabled=True
UltimateWebView1.Settings.SupportMultipleWindows=True
txtUrl.Text="https://zomato.com/partners"
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
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)
End Sub
Private Sub UltimateWebView1_FileDownloadInitialized (DownloadProperties1 As DownloadProperties) 'Works from API level 1 and above. DownloadListener required.
Log("Download INITIALIZED")
'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)
End Sub
Private Sub UltimateWebView1_FileDownloadStarted (DownloadProperties1 As DownloadProperties) 'Works from API level 9 and above. DownloadListener required.
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
Private Sub UltimateWebView1_FileDownloadCompleted (Success As Boolean, DownloadProperties1 As DownloadProperties) 'Works from API level 9 and above. DownloadListener required.
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 (Url As String) As Boolean 'Works from API level 1 to API level 23. WebViewClient required.
'Log("OverrideUrl")
'Log(Url)
Return False
End Sub
Private Sub UltimateWebView1_OverrideUrl2 (WebResourceRequest1 As WebResourceRequest) As Boolean 'Works from API level 24 and above. WebViewClient required.
'Log("OverrideUrl")
'Log(WebResourceRequest1.GetUrl)
Return False
End Sub
Private Sub UltimateWebView1_OverrideUrlWithExternalAppIntent (Url As String, ExternalAppIntent As Intent) As Boolean 'Works from API level 1 to API level 23. WebViewClient required.
'Log("OverrideUrlWithExternalAppIntent")
'Log(Url)
StartActivity(ExternalAppIntent)
Return True
End Sub
Private Sub UltimateWebView1_OverrideUrlWithExternalAppIntent2 (WebResourceRequest1 As WebResourceRequest, ExternalAppIntent As Intent) As Boolean 'Works from API level 24 and above. WebViewClient required.
'Log("OverrideUrlWithExternalAppIntent")
'Log(WebResourceRequest1.GetUrl)
StartActivity(ExternalAppIntent)
Return True
End Sub
Private Sub UltimateWebView1_FileChooserInitialized (FilePathCallback As Object, FileChooserParams1 As FileChooserParams) 'Works from API level 21 and above. WebChromeClient required.
UltimateWebView1.FileChooserStart(FilePathCallback,FileChooserParams1,False)
End Sub
Private Sub UltimateWebView1_PageFinished (Url As String) 'Works from API level 1 and above. WebViewClient required.
'Log(Url)
End Sub
Private Sub UltimateWebView1_PageStarted (Url As String, FavIcon As Bitmap) 'Works from API level 1 and above. WebViewClient required.
Log(Url)
'If FavIcon<>Null Then
'do stuff...
'End If
End Sub
Private Sub UltimateWebView1_ReceivedIcon (Icon As Bitmap) 'Works from API level 1 and above. WebChromeClient required.
'If Icon<>Null Then
'do stuff...
'End If
End Sub
'Very important event for UltimateWebView permissions request (Camera, Geolocation, Microphone, Write Storage itd.)!!!
Private Sub UltimateWebView1_PermissionRequest (RequestedPermission As String) 'Works from API level 21 and above. WebChromeClient required.
Dim Permissions As RuntimePermissions
Permissions.CheckAndRequest(RequestedPermission)
Wait For Activity_PermissionResult (Permission As String, result As Boolean)
UltimateWebView1.GrantPermission(result)
End Sub
Private Sub UltimateWebView1_ReceivedError (ErrorCode As Int, Description As String, FailingUrl As String) 'Works from API level 1 to API level 23. WebViewClient required.
Log("error " & ErrorCode)
'Log(ErrorCode)
'Log(Description)
'Log(FailingUrl)
End Sub
Private Sub UltimateWebView1_ReceivedError2 (WebResourceRequest1 As WebResourceRequest, WebResourceError1 As WebResourceError) 'Works from API level 23 and above. WebViewClient required.
'Log("ReceivedError")
'Log(WebResourceRequest1.GetUrl)
'Log(WebResourceError1.Description)
'Log(WebResourceError1.ErrorCode)
End Sub
Private Sub UltimateWebView1_ReceivedHttpError (WebResponseRequest1 As WebResourceRequest, WebResourceResponse1 As WebResourceResponse) 'Works from API level 23 and above. WebViewClient required.
'Log("ReceivedHttpError")
'Log(WebResponseRequest1.GetUrl)
'Log(WebResourceResponse1.Encoding)
'Log(WebResourceResponse1.StatusCode)
End Sub
Private Sub UltimateWebView1_ReceivedHttpAuthRequest (HttpAuthHandler1 As HttpAuthHandler, HttpAuthRequestProperties1 As HttpAuthRequestProperties) 'Works from API level 1 and above. WebViewClient required.
Log("ReceivedHttpAuthRequest")
Log(HttpAuthRequestProperties1.Host)
Log(HttpAuthRequestProperties1.Realm)
End Sub
Private Sub UltimateWebView1_ReceivedLoginRequest (LoginRequestProperties1 As LoginRequestProperties) 'Works from API level 12 and above. WebViewClient required.
Log("ReceivedLoginRequest")
Log(LoginRequestProperties1.Realm)
Log(LoginRequestProperties1.Account)
Log(LoginRequestProperties1.Args)
End Sub
Private Sub UltimateWebView1_ShouldInterceptRequest (Request As WebResourceRequest) As WebResourceResponse 'Works from API level 21 and above. WebViewClient required.
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 'Works from API level 1 and above. WebChromeClient required.
Log(JsProperties1.Message)
'Log("JsAlert")
'Log(JsProperties1.Url)
'Log(JsProperties1.Message)
'Log(JsProperties1.DefaultValue)
'JsResult1.Confirm
'Return True
Return False
End Sub
Private Sub UltimateWebView1_JsBeforeUnload (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean 'Works from API level 1 and above. WebChromeClient required.
'Log("JsBeforeUnload")
'Log(JsProperties1.Url)
'Log(JsProperties1.Message)
'Log(JsProperties1.DefaultValue)
'JsResult1.Confirm
'Return True
Return False
End Sub
Private Sub UltimateWebView1_RenderProcessGone (DidCrash As Boolean, RendererPriorityAtExit As Int) 'Works from API level 26 and above. WebViewClient required.
Log(DidCrash)
Log(RendererPriorityAtExit)
End Sub
Private Sub UltimateWebView1_JsConfirm (JsProperties1 As JsProperties, JsResult1 As JsResult) As Boolean 'Works from API level 1 and above. WebChromeClient required.
'Log("JsConfirm")
'Log(JsProperties1.Url)
'Log(JsProperties1.Message)
'Log(JsProperties1.DefaultValue)
'JsResult1.Confirm
'Return True
Return False
End Sub
Private Sub UltimateWebView1_CreateChildWindow (IsDialog As Boolean, IsUserGesture As Boolean) As UltimateWebView 'Works from API level 1 and above. WebChromeClient required.
Log("Added New Child Window")
'Return Null if you do not want to create child window. Page will not be loaded!
Dim NewUltimateView As UltimateWebView
NewUltimateView.Initialize(Me,"NewUltimateView")
NewUltimateView.EnableSlowWholeDocumentDraw
NewUltimateView.Settings.ImportSettingsFrom(UltimateWebView1) 'Import settings from main UltimateWebView without referencing.
NewUltimateView.WebViewClientEnabled=True
NewUltimateView.WebChromeClientEnabled=True
NewUltimateView.DownloadListenerEnabled=True
NewUltimateView.CookieManager.AcceptCookies=True
NewUltimateView.CookieManager.AcceptFileSchemeCookies=True
NewUltimateView.CookieManager.AcceptThirdPartyCookies=True
NewUltimateView.CookieManager.Flush
Return NewUltimateView 'Return created UltimateWebView like child window. Library will do the rest. You can initialize all needed events for this child.
End Sub
Private Sub NewUltimateView_FileDownloadInitialized (DownloadProperties1 As DownloadProperties) 'Works from API level 1 and above. DownloadListener required.
UltimateWebView1.StartFileDownload(DownloadProperties1,"Test",True,True)
End Sub
Sub NewUltimateView_PageFinished (Url As String)
Log("ChildFinishedPage: " & Url)
End Sub
Sub NewUltimateView_OverrideUrl (WebResourceRequest1 As WebResourceRequest) As Boolean
Log("OverridenChildUrl: " & WebResourceRequest1.GetUrl)
Return False
End Sub