android - 设置/更改更改 Android 中的 WebView 用户代理

标签 android android-webview user-agent

我有一个网站应该只在我的应用程序中使用 WebView,否则我的网站会将用户重定向到他可以下载我的应用程序的页面。

那么,如何在 WebView 中更改此 UA?

此外,由此可能引起的问题是什么?

最佳答案

您可以使用 setUserAgent来自 android.webkit.WebSettings,简单示例:

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 并不“完美”,而是为此目的而创建的,识别浏览器。

关于android - 设置/更改更改 Android 中的 WebView 用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35866310/

相关文章:

java - 创建在后台播放音频的服务

java - 为什么我在 avd 应用程序菜单中看不到我的应用程序?

java - 将自定义 header 添加到 WebView 资源请求 - android

Android:WebView onClick 不起作用?

android - 从 fragment 设置 WebView 的页面标题

firefox - NS_ERROR_XPC_NOT_ENOUGH_ARGS : Not enough arguments [nsIWebBrowserPersist. saveURI],第 5 行(错误代码:-1001),带有 imacros

android - 尝试从应用程序内下载 .apk 文件。获取 "client identification header"错误

html - IE11 缺少主要元素的用户代理样式(显示 : block;)

android - 使用 Play 核心库验证非 Google Play 应用安装

android - 如何从原始资源中获取 uri