0

在服务器上修改 html 文件时,所做的更改会显示在 Android 版本 2.2 和 Android 版本 2.3.3 中,但不会显示在 Android 版本 4.0.4 中。例如,显示旧文本而不是新文本。

我的代码是:

public class MywebviewActivity extends Activity {

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

this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.mywebview);
final Activity MywebviewActivity = this;        
  // Makes Progress bar Visible
  getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
  android.webkit.WebView wv = 
  (android.webkit.WebView)this.findViewById(R.id.myWebView); 
  wv.setWebChromeClient(new WebChromeClient() {     
  public void onProgressChanged(WebView view, int progress)   
  {
   //Make the bar disappear after URL is loaded, and changes string to Loading...
      MywebviewActivity.setTitle("Loading...");
      MywebviewActivity.setProgress(progress * 100); //Make the bar disappear after URL      is loaded

  // Return the app name after finish loading
  if(progress == 100)
      MywebviewActivity.setTitle(R.string.web_app_name);
    }
  });

  wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  wv.getSettings().setJavaScriptEnabled(true);
  wv.setHorizontalScrollBarEnabled(false);
  wv.loadUrl("http://mypagename.com/android/server/app/ver10/page1.html");

}

public void onBackPressed() {
android.os.Process.killProcess(android.os.Process.myPid());
return;
}
4

2 回答 2

0

在加载 WebView 之前尝试清除缓存:

...
android.webkit.WebView wv = (android.webkit.WebView)this.findViewById(R.id.myWebView);
wv.clearCache(true);
wv.setWebChromeClient(new WebChromeClient() {
...

http://developer.android.com/reference/android/webkit/WebView.html#clearCache(boolean )

于 2012-10-04T19:59:38.383 回答
0

尝试在WebViewSettings不缓存数据中设置一个属性:

wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
于 2012-10-04T20:13:36.233 回答