获取用户代理编程 [英] Retrieve User-Agent programatically

查看:182
本文介绍了获取用户代理编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来检索浏览器的用户代理,而无需在活动的一个的WebView

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

我知道这是可以通过的WebView 来得到它:

I know it is possible to get it via WebView:

WebView view = (WebView) findViewById(R.id.someview);
String ua = view.getSettings().getUserAgentString() ;

但在我来说,我没有/需要的WebView对象,我不希望创建它只是用于获取用户代理字符串。

But in my case I don't have/need a webview object and I don't want to create it just for retrieving user-agent string.

推荐答案

如果你不这样做的有无一个你可以尝试把它像这样

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

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

编辑 -

Edit-

该文档的 getUserAgentString()表示,

返回的WebView的用户代理字符串

所以,我不认为你可以得到它,除非你声明的。有人纠正我,如果我错了,

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

这篇关于获取用户代理编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆