How to open desktop site in webview in android

后端 未结 5 1143
暗喜
暗喜 2020-12-20 02:01

I need to open desktop site in android webview for that i have tried as below but it is not working.

String newUA= \"Mozilla/5.0 (X11; U; Linux i686; en-US;          


        
相关标签:
5条回答
  • 2020-12-20 02:21

    You can use setDesktopMode(true) from this WebView subclass or read how it's implemented. What is does is (a) set the user-agent not to include the words "mobile" or "Android" and (b) set the viewport to a larger width.

    0 讨论(0)
  • 2020-12-20 02:26

    For Mobile User-Agent

    webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 4.4; en-us; Nexus 4 Build/JOP24G) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");

    For Desktop site Agent

    browser.getSettings().setUserAgentString("Mozilla/5.0 (Linux; diordnA 7.1.1; suxeN 6 Build/N6F26U; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 eliboM Safari/537.36");

    A lot of searches this code fine working on Android webview.

    0 讨论(0)
  • 2020-12-20 02:31

    Try this:

        webView = (WebView)findViewById(R.id.webView1);
        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)
  • 2020-12-20 02:43

    This is working for me: refer to this as mentioned by @saurabh gutpa as well

    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);
    }
    
    0 讨论(0)
  • 2020-12-20 02:44

    This is the perfect solution:

     private static final String DESKTOP_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36";
     private static final String MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; U; Android 4.4; en-us; Nexus 4 Build/JOP24G) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
    
     //Choose Mobile/Desktop client.
     WebSettings settings = mWebView.getSettings();
     settings.setUserAgentString(DESKTOP_USER_AGENT);
    
    0 讨论(0)
提交回复
热议问题