Android mobile user agent?

前端 未结 4 1919
萌比男神i
萌比男神i 2021-01-01 18:16

I\'m currently making an android application for a forum, basically it just loads the website in a webview and that works fine and all, but I\'m trying to add an option to v

相关标签:
4条回答
  • 2021-01-01 18:32

    This is an example of user agent for android:

    Mozilla/5.0 (Linux; U; Android 2.2; en-gb; Nexus One Build/FRF50) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

    And you can use simply:

    myWebView.getSettings().setUserAgentString("Android");
    
    0 讨论(0)
  • 2021-01-01 18:39

    Create a new string In the activity of the webview, create a new string,

    String MyUA = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 " +
            "(KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
    

    So we created a string for user agent, the user agent defined in the string is of a desktop browser user agent, with this user agent set – your Android browser will load desktop version of websites. You can change this user agent to other user agents you like.

    So we set the string, now let’s call it

    web.getSettings().setUserAgentString(MyUA)
    

    Here we called the string that we have set, it is ready now.

    This code can be inside the oncreate method of the web activity.

    0 讨论(0)
  • 2021-01-01 18:52

    As 2019 for Android devices have a look to: https://developer.chrome.com/multidevice/user-agent

    So as documentation says:

    WebView UA in Lollipop and Above

    In the newer versions of WebView, you can differentiate the WebView by looking for the wv field as show in bold below.

    Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36

    0 讨论(0)
  • 2021-01-01 18:53

    Use webview.getSettings().setUserAgent(int); in the int parameter ,0 is a mobile browser while 1 is desktop browser

    0 讨论(0)
提交回复
热议问题