7

我有一个名为 Vane 的网络应用程序(链接)。它在我的手机(三星 S3)和某些设备上正常工作,但在某些设备上它只加载 html 部分没有 js 没有 css ..

有什么理由吗?这是我的第一个应用程序,我对 java 了解不多。图片:

这就是它应该如何工作(三星s3)

在此处输入图像描述

这就是它在其他一些设备中的外观,只有 html(Xtouch 手机)

在此处输入图像描述

网页浏览代码:

package com.expedyte.vane;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebStorage;


public class IWeather extends Activity {


    public class GeoWebViewClient extends WebViewClient {
       @Override
       public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // When user clicks a hyperlink, load in the existing WebView
        view.loadUrl(url);
       return true;
   }
}


public class GeoWebChromeClient extends WebChromeClient {
    @Override
    public void onGeolocationPermissionsShowPrompt(String origin,
            GeolocationPermissions.Callback callback) {

        callback.invoke(origin, true, false);
    }
}

WebView mWebView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_iweather);
    WebView mWebView = (WebView) findViewById(R.id.web_engine);

    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setAppCacheEnabled(true);        
    mWebView.getSettings().setDatabaseEnabled(true);
    String databasePath = this.getApplicationContext().getDir("database",Context.MODE_PRIVATE).getPath(); 
    mWebView.getSettings().setDatabasePath(databasePath);
    mWebView.setWebViewClient(new GeoWebViewClient());
    // Below required for geolocation
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setGeolocationEnabled(true);
    mWebView.setWebChromeClient(new GeoWebChromeClient()
    { 
        public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { 
                quotaUpdater.updateQuota(5 * 1024 * 1024); 
            } 
        }); 

    mWebView.loadUrl("file:///android_asset/www/weather/index.html");
}
}

html代码:

<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="/vane/we.ico" type="image/x-icon" />
<link rel="stylesheet" href="swiper.css">
<link rel="stylesheet" href="style.css?1">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet'>
<script src="jquery.js"></script>
<script src="plugins.js"></script>
<script src="script.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCaF3Xp-29k7VdixW4PzUU4wmtRAM7T-RA&sensor=false"></script>
<meta name="viewport" content="initial-scale=1, user-scalable=no">
  </head>
  <body>
  <div id="loader"><img src="load.png"></div>


<div id="weather">
    <div class="swiper-container swiper-1" id="mainswipe">
            <div class="swiper-wrapper">
                <div class="swiper-slide ordinary">
                    <div class="swiper-container swiper-2">
                        <div class="swiper-wrapper" id="scroller">

                        </div>
                    </div>
                </div>
                <div class="swiper-slide ordinary" id="places_main">
                    <div class="card">
                    <input type="text" class="search" id="search" onclick="if(this.value=='Enter a place.'){this.value=''; this.select()} else    {this.select()}" value="Enter a place."></input><div class="go" onclick="addPlace()">+</div>
                    <div id="placeholder">
                        <div class="swiper-container places">
                            <div class="swiper-wrapper" id="places">
                            </div>
                        </div>
                    </div>
                    </div>
                </div>
            </div>
        </div></div>
<div id="rate">
        <div id="rate_title">Rate Us</div>
        <div id="rate_content">Show us how much you love this app by rating us on the app store. Thank you for checking us out.</div>
        <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=630139527&pageNumber=0&sortOrdering=1&type=Purple+Software&mt=8"><div class="button confirm">Rate Us</div></a>
        <div class="button remind" onclick="$('#rate').fadeOut()">Remind me later</div>
        <div class="button never" onclick="never_again()">Never ask me again</div>
  </div>
  <div id='alertbox'>
        <div id='alertheader'>ALERT</div>
        <div id='alertcontent'>
                <div></div>
        </div>
        <div class='close' onclick='cancelalert()'>Close</div>
  </div>
  <div id="info">
  <div class="half">
        <div id="header"><div id="back" onclick="hide_info()">Back</div>About</div>
        <div id="video">
            <iframe src="http://www.youtube.com/embed/KLbYRPIZ5-4" frameborder="0" allowfullscreen></iframe>
        </div>
  </div>
  <div id="scroller">
        <div class="setting">
            <div class="label">Unit</div>
            <div id="unit">C</div><div class="degree">&ordm;</div>
            <div class="switch" onclick="changeUnit()"><div id="toggle"></div></div>
        </div>
  </div>
  </div>
  </body>
  </html>
4

3 回答 3

1

你编辑代码 +

super.onStart();

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

//enable JavaScript ***
webView.getSettings().setJavaScriptEnabled(true);

webView.loadUrl("file:///android_asset/index.html");
于 2015-01-18T07:16:11.123 回答
0

如果 javascript 不起作用,只需添加以下内容:

webView.getSettings().setJavaScriptEnabled(true);
于 2020-08-28T09:14:56.473 回答
-2

一些 android 版本的文件协议中存在一个已知错误。如果您使用 url 参数引用文件,则会出现 HTTP 404(未找到文件)并且未加载文件。

在您的情况下,“style.css?1”没有被加载。

克服 Honeycomb 和 Ice Cream Sandwich 损坏的 WebView URL

于 2013-07-12T06:02:19.433 回答