Webview 桌面网站无法在 Android 中运行 [英] Webview Desktop website won't work in Android

查看:28
本文介绍了Webview 桌面网站无法在 Android 中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

部分是作为学习一些 Android 编程的练习,部分是因为我希望我在 Android 手机上有一个 WhatsApp 客户端,我正在尝试创建一个应用程序,我可以亲自将它用作我的手机的 WhatsApp 客户端.它所做的只是在 UIWebView 中加载 web.whatsapp.com 桌面站点,如下所示:

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);

    }
});

这个没问题.如果 Activity 加载 Web 视图而不是像服务器检测到移动设备时通常发生的那样重定向到原始页面,它实际上第一次单独加载正确的 Web 应用程序.但是,与其显示实际页面,不如将我重定向到另一个页面,

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,

现在,如果我在我的手机上使用 chrome 中的 WhatsApp Web(并请求桌面版本),它运行得非常好,我通过设置 UserAgent 为我的 UIWebView 请求桌面站点.现在,我想知道为什么它不能在 WebView 中工作,以及是否需要设置一些其他标题或值才能说服应用程序在我的 WebView 或清单中工作.

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.

我不熟悉 Android 开发.我在网上搜索过这个问题的答案,但找不到.

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

推荐答案

你能不能改变一下String ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101Firefox/4.0";并尝试.

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.

这篇关于Webview 桌面网站无法在 Android 中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆