0

我是 android 平台上的新开发人员,现在我有 Sony Xperia ST26,我注意到浏览器(com.android.browser)和 Chrome(com.android.chrome)之间的差异用户代理。

Chrome:  Mozilla/5.0 (Linux; Android 4.0.4; **ST26i Build**/11.0.A.7.5) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19

Browser:  Mozilla/5.0 (Linux; U; Android 4.0.4; iw-il; **SonyST26i Build**/11.0.A.7.5) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

我需要一种方法来获取这些用户代理,

我尝试使用 WebView 像这样:

userAgent = new WebView(this).getSettings().getUserAgentString();

并且该字符串是“默认”用户 agnet 而不是嵌入式浏览器。

我也尝试这样做,现在浏览器(应用程序)显示正确的用户 agnet,但我需要将此 HTML 网站插入字符串。

String url = "http://whatsmyuseragent.com/";
String packageName = "com.android.browser";  
//String packageName ="com.android.chrome";
Intent internetIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(url)); 
internetIntent.setPackage(packageName);
startActivity(internetIntent); 

有人有想法吗?

4

1 回答 1

0

It looks like you are trying to get the user agent of the embedded webview. If you have Chrome installed, the embedded WebView still remains the same webview that is distributed with the OS. There is no Chromium based WebView.

You can also use System.getProperty("http.agent") as outlined in http://cdrussell.blogspot.co.uk/2012/09/programmatically-get-user-agent-string.html

于 2013-03-05T12:15:03.097 回答