【问题标题】:Want to load desktop version in my webview using uastring想使用 uastring 在我的 webview 中加载桌面版本
【发布时间】:2011-11-29 11:14:17
【问题描述】:

我正在为三星 Galaxy、moto xoom 和 kindle fire 等平板电脑开发应用程序。

我的 webview 没有加载我提供的桌面版本的 url。

我尝试通过设置用户代理,但我不知道确切的“ua 字符串”将解决我的问题。当我记录 ua 字符串时,我得到了以下内容

代码:

String ua = m_webview.getSettings().getUserAgentString() ;
Log.i("AboutActivity", "UA = "+ua) ;

UA 字符串:

UA = Mozilla/5.0 (Linux; U; Android 3.1; en-US; GT-P7500 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13

我在某处读到需要删除 ua 字符串中的“mobile”,但在打印的 ua 字符串中没有得到“mobile”。

我已经通过在其中添加桌面尝试了以下 ua 字符串,即使它没有出现

 String ua = "Mozilla/5.0 (Linux; U; Android 3.1; en-US; GT-P7500 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Desktop Safari/534.13";
 mWebview.getSettings().setUserAgentString(ua);

【问题讨论】:

    标签: android webview user-agent


    【解决方案1】:

    他们可能知道您在使用手机,因为您在用户代理中有Android。尝试更多的桌面浏览器,例如:

    String ua = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
    

    【讨论】:

      【解决方案2】:

      这对我有用:参考this

          public void setDesktopMode(final boolean enabled) {
          final WebSettings webSettings = webview.getSettings();
      
          final String newUserAgent;
          if (enabled) {
              newUserAgent = webSettings.getUserAgentString().replace("Mobile", "eliboM").replace("Android", "diordnA");
          }
          else {
              newUserAgent = webSettings.getUserAgentString().replace("eliboM", "Mobile").replace("diordnA", "Android");
          }
      
          webSettings.setUserAgentString(newUserAgent);
          webSettings.setUseWideViewPort(enabled);
          webSettings.setLoadWithOverviewMode(enabled);
          webSettings.setSupportZoom(enabled);
          webSettings.setBuiltInZoomControls(enabled);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-18
        • 2012-08-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多