Android Question View the Desktop version of a site with WebView

Discussion in 'Android Questions' started by Nestor71, Aug 5, 2019.

  1. Nestor71

    Nestor71 Member Licensed User

  2. JohnC

    JohnC Well-Known Member Licensed User

    Last edited: Aug 5, 2019
    Erel and José J. Aguilar like this.
  3. Nestor71

    Nestor71 Member Licensed User

    Thanks for the reply, I put this code but it always opens the mobile site, where am I wrong?

    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
        
    Activity.LoadLayout("Main")
            
        
    Dim Obj1 As Reflector
        Obj1.Target = WebView1
        
    Msgbox(Obj1.ToString, "Target")
        Obj1.Target = Obj1.RunMethod(
    "getSettings")
        
    Msgbox(Obj1.ToString, "Settings")
      
        
    Msgbox(Obj1.RunMethod("getUserAgentString"), "User agent")
      
        Obj1.RunMethod2(
    "setUserAgentString""Desktop""java.lang.String")
        
        WebView1.LoadUrl(
    "https://www.b4x.com/android/forum/")
        
    End Sub
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. Nestor71

    Nestor71 Member Licensed User

    I checked the thread I put this code but when I start the app it closes

    Code:
    Dim jo As JavaObject = WebView1
    Dim settings As JavaObject = jo.RunMethod("getSettings"Null)
    settings.RunMethod("setUseWideViewPort"Array(True))
    settings.RunMethod("setLoadWithOverviewMode"Array(True))
     
  6. JohnC

    JohnC Well-Known Member Licensed User

    Try using this webviewSettings library:

    https://www.b4x.com/android/forum/threads/webviewsettings.12929/

    It will allow you to set various settings like the user agent, wideviewport, overviewmode using regular methods instead of using a java object (like you did in the previous code above).

    See if it works better for you.
     
    Last edited: Aug 7, 2019
    Erel likes this.
  7. Nestor71

    Nestor71 Member Licensed User

    Thanks, with the address https://www.b4x.com/android/forum/ it works but if I put the address I want it comes out written Browser not supported we recommend to use the following Browsers: Google Chrome, Mozilla Firefox, Opera, Microsoft Edge, Safari.
    Is there a way to solve it?
     
  8. JohnC

    JohnC Well-Known Member Licensed User

    The WebviewSettings library I mentioned above has a method to set the useragent:

    Code:
    wvs.setUserAgentString(wv,"xxxx")
    Do a google search of different user agent strings and see is any of them will give you the result you are looking for.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice