Android Question ultimatewebview2

Situ LLC

Active Member
Licensed User
Good morning listers

I am using ultimatewebview2 an example from the forum. My issues are when I open the link where I have a map running on a server with openmaps.
In the browser it shows me the map, with webview it shows everything except the map. On the server it runs with java scripts called from an html.

Should I add some other instruction or parameter? I have to add code so that it runs correctly.
There 2 screen shots one show corrected the map on the navegator other from the webview.
Any help will be appreciated it
Thanks

From :posted




ultimatewebview:
#Region Shared Files
'#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private txtUrl As EditText
    Private rp As RuntimePermissions
    Private Settings As WebSettings
    Private CookieM As CookieManager
    Private WebViewClient As UltimateWebViewClient
    Private WebChromeClient As UltimateWebChromeClient
    Private DownloadListener As UltimateDownloadListener
    Private fp As FileProvider
    Public WebView1 As WebView ' Object added through Designer
    Private titulo As Label
    Public   IconsFont, IconsFont1 As B4XFont
 
    Public  B4XSlideMenu1 As B4XSlideMenu
    Public  ActionBar As B4XView
    Public  btnShow As Button
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
  
    fp.Initialize
  
      
    WebViewClient.Initialize2("WebView1",WebView1)
    '-------Or else-----
    'WebViewClient.Initialize("WebView1").ImplementInWebView(WebView1)
  
'    WebChromeClient.Initialize2("WebView1",WebView1).AllowFullScreenVideo(True,False) 'AllowFullScreenVideo only if you need, it is not necessary to set.
    '-------Or else-----
'    WebChromeClient.Initialize("WebView1").AllowFullScreenVideo(True,False).ImplementInWebView(WebView1)
  
'    DownloadListener.Initialize2("WebView1",WebView1)
    '-------Or else-----
    DownloadListener.Initialize("WebView1").ImplementInWebView(WebView1)
  
    Settings.Initialize(WebView1)
    CookieM.Initialize(WebView1)
  
    Settings.AllowContentAccess=True
    Settings.AllowFileAccess=True
    Settings.AllowFileAccessFromFileURLs=True
    Settings.AllowUniversalAccessFromFileURLs=True
    Settings.BuiltInZoomControls=False
    Settings.JavaScriptEnabled=True
    Settings.DomStorageEnabled=True
    Settings.JavaScriptCanOpenWindowsAutomatically=True
    Settings.MediaPlaybackRequiresUserGesture=False
    Settings.SaveFormData=True
    Settings.GeolocationEnabled=True
    Settings.SupportMultipleWindows=True
    Settings.FantasyFontFamily=True
    Settings.AllowContentAccess=True
  
    CookieM.AcceptCookies=True
    CookieM.AcceptFileSchemeCookies=True
    CookieM.AcceptThirdPartyCookies=True
    Dim urls As String = "https://dmylink"
    CookieM.SetCookie(urls,1)
    CookieM.AcceptCookies=True
  
    CookieM.Flush
  
  
    Dim jo As JavaObject

     jo.InitializeContext
    jo = Me
    jo.RunMethod("doSettings",    Array(WebView1))
  
    WebView1.LoadUrl(urls )
  
    Incio_slidemenu

End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub btnGo_Click
    WebView1.LoadUrl(txtUrl.Text)
End Sub

Private Sub WebView1_PermissionsRequest (RequestedRuntimePermissions As List, Request As PermissionRequest) 'Works from API level 21 and above.
    For Each permission As String In RequestedRuntimePermissions
        Log(permission)
        rp.CheckAndRequest(permission)
        Wait For B4XPage_PermissionResult (permission As String, Result As Boolean)
        If Result=False Then
            Request.Deny
            Return
        End If
    Next
    Request.Grant(Request.Resources)
End Sub

Private Sub WebView1_GeolocationPermissionRequest (Origin As String, Callback As GeolocationPermissionCallback) 'Works from API level 5 and above.
    Msgbox2Async("This web page requests geolocation permission.", "Geolocation permission required","Allow All Time", "Allow Once", "Deny",Null,False)
    Wait For Msgbox_Result(mResult As Int)
    If mResult=DialogResponse.CANCEL Or mResult=DialogResponse.POSITIVE Then
        Dim RequestedRuntimePermissions As List
        RequestedRuntimePermissions.Initialize
        RequestedRuntimePermissions.Add(rp.PERMISSION_ACCESS_FINE_LOCATION)
        RequestedRuntimePermissions.Add(rp.PERMISSION_ACCESS_COARSE_LOCATION)
        For Each permission As String In RequestedRuntimePermissions
            rp.CheckAndRequest(permission)
            Wait For B4XPage_PermissionResult (permission As String, Result As Boolean)
            If Result=False Then
                Callback.Invoke(Origin,False,False)
                Return
            End If
        Next
        If mResult=DialogResponse.POSITIVE Then
            Callback.Invoke(Origin,True,True)
        Else
            Callback.Invoke(Origin,True,False)
        End If
    Else
        Callback.Invoke(Origin,False,False)
    End If
End Sub

Private Sub WebView1_OverrideUrl (Request As WebResourceRequest) As Boolean 'Works from API level 1 and above.
    'Log("OverrideUrl = " & Request.Url)
    If Request.HasExternalAppIntent Then
        StartActivity(Request.ExternalAppIntent)
        Return True
    End If
    Return False
End Sub


Private Sub WebView1_FileDownloadInitialized (Properties As DownloadProperties) 'Works from API level 1 and above.
    Log("FileDownloadInitialized")
    DownloadListener.StartFileDownload(Properties,"","hello",True,True)
End Sub

Private Sub WebView1_FileDownloadStarted (Properties As DownloadProperties) 'Works from API level 9 and above.
    Log("FileDownloadStarted, ID=" & Properties.DownloadID)
End Sub

Private Sub WebView1_FileDownloadCompleted (Success As Boolean, Properties As DownloadProperties) 'Works from API level 9 and above.
    Log("FileDownloadCompleted, ID=" & Properties.DownloadID)
End Sub

Private Sub WebView1_PageFinished (Url As String) 'Works from API level 1 and above.
    'Log("PageFinished = " & Url)
    txtUrl.Text=Url
End Sub

Private Sub WebView1_CreateWindow (OverridenRequest As WebResourceRequest, ChildWebView As WebView, IsDialog As Boolean, IsUserGesture As Boolean) As Boolean 'Works from API level 1 and above. Return True if you want to consume ChildWebView, False to destroy. SupportMultipleWindows option must be enabled. You can add the newly created WebViewObject to Layout manualy, or use UltimateWebView's AddChildWindow method.
    Log("WebkitWebView1_CreateWindow")
    If IsUserGesture=False Then Return False 'Try to prevent an unwanted comercial popup's.
  
    'Add ChildWebView to layout manualy. You must set object size and position. Also, future control of the object is completely manual.
  
    Return True
End Sub

Private Sub WebView1_ShowFileChooser (FilePathCallback As ValueCallbackUri, Params As FileChooserParams) 'Works from API level 21 and above. FilePathCallback.OnReceiveValue must be executed with value from file chooser, or null to abort.
    WebChromeClient.ShowDefaultAppChooser(FilePathCallback,Params,False,fp.SharedFolder)
  
    '------------------StartActivityForResult library required to execute code below ("https://www.b4x.com/android/forum/threads/startactivityforresult-lib.157837/")-------------------
    'Dim ActForRes As StartActivityForResult
    'ActForRes.Initialize("ION")
    'ActForRes.Start2(Params.Intent,1,Array(FilePathCallback))
End Sub

'------------------StartActivityForResult library required to execute below event-------------------
'Private Sub ION_OnActivityResult (RequestCode As Int, ResultCode As Int, Data As Intent, ExtraParams() As Object)
'    Log("ION_OnActivityResult_RequestCode = " & RequestCode)
'    Dim ret As Object=FileChooserParams.ParseResult(ResultCode,Data)
'    ExtraParams(0).As(ValueCallbackUri).OnReceiveValue(ret)
'End Sub

Private Sub WebView1_ShouldInterceptRequest (Request As WebResourceRequest) As WebResourceResponse 'Works from API level 11 and above. From Api level 11 to 20, passed WebResourceRequest contains only Url.
    'Log("ShouldInterceptRequestUrl = " & Request.Url)
    Return Null
End Sub



Private Sub WebView1_ReceivedClientCertRequest (Request As ClientCertRequest) 'Works from API level 21 and above.
    Log("-------ReceivedClientCertRequest---------")
    Request.Ignore
End Sub

Private Sub WebView1_ConsoleMessage (Message As ConsoleMessage) As Boolean 'Works from API level 8 and above.
    'Log(Message.Message)
    Return False
End Sub




Sub Incio_slidemenu
    IconsFont =  xui.CreateFont(Typeface.LoadFromAssets("icomoon.ttf"),64)
    IconsFont1 =  xui.CreateFont(Typeface.LoadFromAssets("IcoMoon-Free.ttf"),64)
  
    'Iniliaze Menu
  
    B4XSlideMenu1.Initialize(Root, Me, "SlideMenu", ActionBar.Height,200)

    'Set imtems menu
    B4XSlideMenu1.AddItem(1,"Recargas",     FontToBitmap(Chr(0xe962), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(2,"GPS &Paradas",     FontToBitmap(Chr(0xe923), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(3,"Configuración", FontToBitmap(Chr(0xe960), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(4,"Cobros DEMO",    FontToBitmap(Chr(0xe954), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(5,"Usuarios",     FontToBitmap(Chr(0Xe98e), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(6,"Comandos ",     FontToBitmap(Chr(0xe944), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(8,"Cédulas",     FontToBitmap(Chr(0xeaad), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(9,"Whatzzap ",     FontToBitmap(Chr(0xe95e), IconsFont1, 30, xui.Color_Black))
'    B4XSlideMenu1.AddItem(9,"Bloquedar Pantalla",     FontToBitmap(Chr(0xe956), IconsFont1, 30, xui.Color_Black))
'    B4XSlideMenu1.AddItem(10,"Contadores ",     FontToBitmap(Chr(0xe9ce), IconsFont1, 30, xui.Color_Black))
'    B4XSlideMenu1.AddItem(11,"Horario Extra ",     FontToBitmap(Chr(0Xe953), IconsFont1, 30, xui.Color_Black))
'    B4XSlideMenu1.AddItem(12,"Tools TC20",     FontToBitmap(Chr(0Xe9ae), IconsFont1, 30, xui.Color_Black))
'    B4XSlideMenu1.AddItem(13,"Lector de Cédulas",     FontToBitmap(Chr(0Xe938), IconsFont1, 30, xui.Color_Black))
    B4XSlideMenu1.AddItem(15,"Salir  ",     FontToBitmap(Chr(0xe900), IconsFont1, 30, xui.Color_Black))
  
  
End Sub

 
Sub btnShow_Click
    If B4XSlideMenu1.isVisible Then
        B4XSlideMenu1.Hide
    Else
        B4XSlideMenu1.Show
    End If
End Sub

 
Sub SlideMenu_Click(Item As Object)
'    ToastMessageShow("Item clicked: " & Item, False)
  
    Dim value As Int
    value = Item
    Select value
        Case 1
'            lecturascanner_Click
'            panel_cobrar
        Case 2
'            B4XPages.ShowPage("paradas")
        Case 3
'            lee_config
        Case 4
'            estados="Modo nfc cobros"
'            StartActivity("NFC")
'            B4XPages.MainPage.estados="Fin Cobros"
        Case 5
'            crea_usuarios
        Case 6
'            Maquinas
        Case 8
'            B4XPages.ShowPage("cedulas")
  
        Case 9
'            camara2_Click
'            test_sendMessage( "51615982792")
'            test_sendMessage( "584245808056")
'            test_sendMessage( "50688176232")
'         
          
        Case 15
'            salir
        Case Else
            Log("Nada en case")
    End Select
  
End Sub
[ATTACH type="full"]159995[/ATTACH]

'Convert fonts a icon bitmap
Public Sub FontToBitmap (FontText As String, FontType As B4XFont , FontSize As Int, FontColor As Int) As B4XBitmap
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 32dip, 32dip)
    Dim cvs1 As B4XCanvas
    cvs1.Initialize(p)
    Dim r As B4XRect = cvs1.MeasureText(FontText, xui.CreateFont2(FontType, FontSize))
    Dim BaseLine As Int = cvs1.TargetRect.CenterY - r.Height / 2 - r.Top
    cvs1.DrawText(FontText, cvs1.TargetRect.CenterX, BaseLine, xui.CreateFont2(FontType, FontSize), FontColor, "CENTER")
    cvs1.Invalidate
    Dim b As B4XBitmap = cvs1.CreateBitmap
    cvs1.Release
    Return b
End Sub



#if Java
    import android.webkit.WebView;
    import android.webkit.WebSettings;

    public void doSettings( WebView wv ) {
       wv.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
       wv.getSettings().setJavaScriptEnabled(true);
       wv.getSettings().setDomStorageEnabled(true);
       wv.clearClientCertPreferences( null );
       wv.clearSslPreferences();
       wv.clearHistory();
       wv.getSettings().setDisplayZoomControls(false);
       wv.getSettings().setBuiltInZoomControls(true);
       wv.getSettings().setAllowFileAccess(true);   // google turns this off by default as of api30
    }
#End If

 

Attachments

  • 1735320165200.png
    151.4 KB · Views: 10
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…