Webview Desktop website won't work in Android

狂风中的少年 提交于 2019-12-24 10:45:49

问题


Partly as an exercise for learning a little Android programming, and partly because I wish I had a WhatsApp client on Android mobile, I am trying to create an app that I can personally use as a WhatsApp client for my mobile. All it does is load up the web.whatsapp.com desktop site in a UIWebView like so:

webView =  findViewById(R.id.wv);
String ua = "user agent string";
webView.getSettings().setUserAgentString(ua);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(" url ");

webView.setWebViewClient(new WebViewClient(){
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        final Uri uri = request.getUrl();
        return true;
    }

    @Override
    public void onPageFinished(WebView view, final String url) {
        webView.clearHistory();
        super.onPageFinished(view, url);

    }
});

This works okay. It does in fact load the correct web app first time alone, if the activity load the web view rather than redirecting to the original page as would usually happen when the server detects a mobile device. However, rather than presenting actual page its redirect me to another page,

Now, if I use WhatsApp Web from chrome on my mobile (and requesting Desktop version), it works perfectly fine, I am requesting the Desktop site for my UIWebView by setting the UserAgent. Now, I am wondering why it would not work in the WebView, and whether perhaps there is some other header or value that needs to be set in order to convince the App to work within my WebView or manifest.

I am unfamiliar with Android development. I have searched the web for an answer to this question but I could not find one.


回答1:


The site likely uses Bootstrap and just proportions the screen based on display size.




回答2:


can you please change String ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101Firefox/4.0"; and try out.



来源:https://stackoverflow.com/questions/47946658/webview-desktop-website-wont-work-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!