Set/Change 在 Android 中更改 WebView 用户代理
Set/Change changing the WebView user agent in Android
我的网站应该只在我的应用程序中使用 WebView,否则我的网站会将用户重定向到他可以下载我的应用程序的页面。
那么,如何在 WebView 中更改此 UA?
此外,由此可能引起的问题是什么?
您可以在您的应用中将任何 POST 参数发送到您的网站。否则您的网站可以确定是从其他浏览器调用的。
Here 是一个示例,可能会对您有所帮助。
您可以使用 android.webkit.WebSettings
中的 setUserAgent
,简单示例:
WebView myWebView = (WebView) findViewById(R.id.myWebView);
WebSettings myWebSettings = myWebView.getSettings();
myWebSettings.setUserAgentString("Foo/Bar"); # Set your custom user-agent
Also, what are the possible issues which can arise from this?
取决于您的操作,userAgent
不是 "perfect",而是为此目的创建的,请识别浏览器。
我的网站应该只在我的应用程序中使用 WebView,否则我的网站会将用户重定向到他可以下载我的应用程序的页面。
那么,如何在 WebView 中更改此 UA?
此外,由此可能引起的问题是什么?
您可以在您的应用中将任何 POST 参数发送到您的网站。否则您的网站可以确定是从其他浏览器调用的。 Here 是一个示例,可能会对您有所帮助。
您可以使用 android.webkit.WebSettings
中的 setUserAgent
,简单示例:
WebView myWebView = (WebView) findViewById(R.id.myWebView);
WebSettings myWebSettings = myWebView.getSettings();
myWebSettings.setUserAgentString("Foo/Bar"); # Set your custom user-agent
Also, what are the possible issues which can arise from this?
取决于您的操作,userAgent
不是 "perfect",而是为此目的创建的,请识别浏览器。