2

我创建了一个项目来测试为什么在 Android 2.3 及更低版本的 WebView 上没有显示网页(空白页)。必须加载的网址是: https ://www.geotrackline.com/android/middleware/TabletGeoFrame.php?user_id=503&method=load

那应该返回一个显示地图的网络。关键是该应用程序在 Android 3.0(在 GalaxyTab 中测试)及更高版本(在 Galaxy Nexus 中测试)运行良好。

这是我的 Java 代码:

WebViewTestActivity.java:

WebView wb;
private static String MAP_URL = "https://www.geotrackline.com/android/middleware/TabletGeoFrame.php?user_id=503&method=load";

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

    setContentView(R.layout.main);

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

    WebSettings settings = wb.getSettings();

    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setBuiltInZoomControls(true);
    settings.setSupportZoom(true);
    settings.setGeolocationEnabled(true);

    wb.loadUrl(MAP_URL);
    wb.setWebChromeClient(new WebChromeClient(){

            public boolean onConsoleMessage(ConsoleMessage cm) {
                Log.e("onConsoleMessage", cm.message() + " -- From line "
                                     + cm.lineNumber() + " of "
                                     + cm.sourceId());
                return true;
            }
     });

控制台消息显示下一个:

06-07 11:15:36.480: E/onConsoleMessage(21930): Uncaught SyntaxError: Unexpected token for -- From line 573 of https://www.geotrackline.com/android/middleware/js/GeoTracking.js
06-07 11:15:36.500: E/onConsoleMessage(21930): Uncaught ReferenceError: GeoTracking is not defined -- From line 15 of https://www.geotrackline.com/android/middleware/TabletGeoFrame.php?user_id=503&method=load
06-07 11:15:36.530: E/onConsoleMessage(21930): Uncaught TypeError: Cannot call method 'sendAJAX' of undefined -- From line 27 of https://www.geotrackline.com/android/middleware/TabletGeoFrame.php?user_id=503&method=load

这是我从 Android 2.3 及以下版本的 url 得到的响应:

<html>
    <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title> :: geotracking :: </title>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false"></script>
        <script language="javascript1.5" src="js/GeoTracking.js" ></script>
        <script>
            var user_id = '503';
            var postn_id = "1323014511956";
            var method="load";
            var func="";
            var map = new GeoTracking("content","","","");
        </script>
        <style>
            body { margin:0; padding:0; }
        </style>
    </head>
    <body onLoad='map.sendAJAX (method, user_id);'>
        <div id="content" style="width:100%; height:100%"></div>
    </body>
</html>

知道发生了什么吗?

提前谢谢,对不起我的英语

4

0 回答 0