Android Question View the Desktop version of a site with WebView

JohnC

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Nestor71

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

B4X:
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
 
Upvote 0

Nestor71

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

B4X:
Dim jo As JavaObject = WebView1
Dim settings As JavaObject = jo.RunMethod("getSettings", Null)
settings.RunMethod("setUseWideViewPort", Array(True))
settings.RunMethod("setLoadWithOverviewMode", Array(True))
 
Upvote 0

JohnC

Expert
Licensed User
Longtime 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:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
The WebviewSettings library I mentioned above has a method to set the useragent:

B4X:
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.
 
Upvote 0
Top