网页流量负载页错误地在Android版本低于4.0 [英] Webview loads page incorrectly on android versions lower than 4.0

查看:180
本文介绍了网页流量负载页错误地在Android版本低于4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网页视图中显示的结果网页,我得到一个奇怪的结果,在Android版本低于4.0。我有一个区别是打印屏幕。

I'm trying to display a result webpage in a Webview and I'm getting a weird result on Android version lower than 4.0. I have a print screen with what the difference is.

它正确地显示在4.0比新版本和它的作品在我的Galaxy S2不错,但它会显示错误的2三星手机采用Android 2.2和2.3,并在模拟器上。我试图仿真器与Android 3.0和我有同样的结果。作为一个说明,网页工程导致在浏览器上正常,我有一个网站做一些重定向,以防帮助的感觉。

It displays correctly on versions newer than 4.0 and it works fine on my Galaxy S2 but it displays wrong on 2 Samsung phones with Android 2.2 and 2.3 and on the emulator. I tried an emulator with Android 3.0 and I had the same result. As a note, the webpage result works fine on the browser and I have a feeling that the website does some redirects, in case that helps.

下面是code我使用加载页面:

Here is the code I'm using to load the page:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.webview);

    WebView webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);

    // Show the web page
    webView.loadDataWithBaseURL(null, MainActivity.content, "text/html",
            "UTF-8", null);

}

图片

任何想法,为什么它不工作一样在所有的Andr​​oid版本?

Any ideas why it doesn't work the same on all Android versions?

更新
据官方消息,我曾尝试使用加载网页视图的多个版本的网站的网址,与不同的设置和网站只是不与Android版本比旧的4.我卡设备正确加载。

UPDATE It's official, I have tried loading the website URL using multiple versions of WebViews, with different settings and the website just doesn't load correctly on devices with Android version older than 4. I'm stuck.

更新1

我注意到,在旧版本中,它不是,它不正确地加载网页,问题是,它会尝试加载网页和网页版没有的移动版本。我试图改变用户代理,但它并没有区别。

I noticed that on older versions it's not that it doesn't load correctly the page, the problem is that it tries to load the web version of the page and not the mobile version. I tried changing the user agent but it made no difference.

更新2

我几乎尝试了所有我能找到网页视图,并加载内容的网站上,我想不出是什么问题。这是我的code现在,虽然它仅适用于已启用Java脚本一样。

I tried almost all I could find on the site about WebViews and loading content and I can't figure out what the problem is. This is my code now, although it works the same only with java script enabled.

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.webview);

    WebView webView = (WebView) findViewById(R.id.webView1);

    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.setPersistentDrawingCache(0);
    webView.setInitialScale(1);
    webView.getSettings().setDefaultTextEncodingName("utf-8");

    String webData = MainActivity.content;

    webData = webData.replace("#", "%23");
    webData = webData.replace("%", "%25");
    webData = webData.replace("\\", "%27");
    webData = webData.replace("?", "%3f");
    webView.getSettings()
            .setUserAgentString(
                    "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");

    webView.loadData(webData, "text/html; charset=UTF-8", null);

}

// webView.loadDataWithBaseURL(MainActivity.url, MainActivity.content,
// "text/html", "UTF-8", null);

// webView.loadData(MainActivity.content, "text/html; charset=utf-8",
// "UTF-8");

有什么我失踪?

另外,如果它会帮助,这是code代表我如何得到HTTP POST响应,我用在web视图中显示:

Also, if it will help, this is the code for how I get the HTTP Post response that I use to display in the webview:

HttpClient httpClient = new DefaultHttpClient();

        HttpPost httpPost = new HttpPost("http://www.fernbus24.de/bus-"
                + vonCopy + "-" + nachCopy);
        url = "http://www.fernbus24.de/bus-" + vonCopy + "-" + nachCopy;

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("_searchbox",
                "d5ed667846"));

        nameValuePairs.add(new BasicNameValuePair("von", von));
        nameValuePairs.add(new BasicNameValuePair("nach", nach));
        nameValuePairs.add(new BasicNameValuePair("datum", datum));
        // etc...
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpClient.execute(httpPost);

            InputStream is = response.getEntity().getContent();
            Log.i("Test", "response status"
                    + response.getStatusLine().getStatusCode());

            InputStreamReader inputStreamReader = new InputStreamReader(is);

            BufferedReader bufferedReader = new BufferedReader(
                    inputStreamReader);

            StringBuilder stringBuilder = new StringBuilder();

            String bufferedStrChunk = null;

            while ((bufferedStrChunk = bufferedReader.readLine()) != null) {
                stringBuilder.append(bufferedStrChunk);
            }

            content = stringBuilder.toString();

            Log.i("Test", "content is " + content);

        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

更新3

我已经尝试设置webView.setInitialScale(50);而我得到这个:

I have tried setting webView.setInitialScale(50); and I am getting this:

推荐答案

您是否已经尝试过

webView.setInitialScale(50);

这篇关于网页流量负载页错误地在Android版本低于4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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