Custom web agent?

straybullet

Member
Licensed User
Longtime User
Is it possible to set webview to have a custom web agent?

I want to restrict traffic to one of my web sites to my application only and figured this would stop 95% of the people from ever accessing it directly.

Based on a custom web agent I would reject all traffic that wasn't from my app.
 

straybullet

Member
Licensed User
Longtime User
Thanks man, but call me stupid.

Do I not need to assign it to a webview somehow ie

webview1.req.SetHeader("User-Agent", "MyAwesomeApp")

Thanks again!

Yes it is possible, you will have to do something like this:
B4X:
req.SetHeader("User-Agent", "MyAwesomeApp")
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
Requires the WebViewSettings library, as NJDude mentioned above, but here is some example code:
B4X:
Sub Globals
    Dim WebView1 As WebView
    Dim wvs1 As WebViewSettings
End Sub

Sub Activity_Create(FirstTime As Boolean)
    WebView1.Initialize("Webview1")
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
    wvs1.setUserAgentString(WebView1, "DESKTOP_USERAGENT")
    '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    WebView1.LoadUrl("http://www.google.com")
End Sub
 
Upvote 0
Top