Android WebView Not Loading Mobile Site

前端 未结 5 1905
长情又很酷
长情又很酷 2021-01-07 05:39

My app shows a list of articles from an RSS feed and when one is selected it shows the article in a web view. The problem is that the web view is displaying the desktop sit

相关标签:
5条回答
  • 2021-01-07 06:21

    As @WarrenFaith pointed out in comments, this might be happening because of the custom User-Agent string that you are setting with

    web.getSettings().setUserAgentString("Android");
    

    Do not set this or make sure your webserver is configured to serve the mobile version of the site when it receives request with user agent as "Android".

    0 讨论(0)
  • 2021-01-07 06:23
      WebSettings settings = view.getSettings();
          settings.setJavaScriptCanOpenWindowsAutomatically(true);
          settings.setSupportMultipleWindows(true);
          settings.setBuiltInZoomControls(true);
          settings.setJavaScriptEnabled(true);
          settings.setAppCacheEnabled(true);
          settings.setAppCacheMaxSize(10 * 1024 * 1024);
          settings.setAppCachePath("");
          settings.setDatabaseEnabled(true);
          settings.setDomStorageEnabled(true);
          settings.setGeolocationEnabled(true);
          settings.setSaveFormData(false);
          settings.setSavePassword(false);
          settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
          // Flash settings
          settings.setPluginState(WebSettings.PluginState.ON);
    
          // Geo location settings
          settings.setGeolocationEnabled(true);
          settings.setGeolocationDatabasePath("/data/data/selendroid");
        } catch (Exception e) {
          SelendroidLogger.error("Error configuring web view", e);
        }
    
    0 讨论(0)
  • 2021-01-07 06:26

    After searching a lot this worked for me -

        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
    
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
    
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.setScrollbarFadingEnabled(false);
    
    0 讨论(0)
  • 2021-01-07 06:27

    Setting setUseWideViewPort to false solved the problem for me:

    mWebView.getSettings().setUseWideViewPort(false);
    
    0 讨论(0)
  • 2021-01-07 06:39

    You just need to do include following line of code and it will be loading mobile site perfectly!

    webView.setInitialScale(1);
    webView.getSettings().setJavaScriptEnabled(true);
    
    0 讨论(0)
提交回复
热议问题