Retrieve User-Agent programmatically

前端 未结 6 1751
天涯浪人
天涯浪人 2020-12-13 17:52

Is there a way to retrieve Browser\'s user-agent without having a WebView in activity?

I know it is possible to get it via WebView:

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 18:43

    If you don't have one you can try taking it like this

    String ua=new WebView(this).getSettings().getUserAgentString();
    

    Edit-

    The doc for getUserAgentString() says

    Return the WebView's user-agent string.

    So i don't think you can get it unless you declare one. Some one correct me if i am wrong

提交回复
热议问题