0

我想制作一个可以在phonegap中离线时保存或加载数据缓存的应用程序,但它不起作用这是我的代码,public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
//super.onCreate(savedInstanceState);
//super.setIntegerProperty("splashscreen", R.drawable.ic_launcher);
//super.loadUrl("http://192.168.43.190/TA/index.php");
//WebView webView = new WebView( context );
super.appView.getSettings().setAppCacheMaxSize( 5 * 1024 * 1024 ); // 5MB
super.appView.getSettings().setAppCachePath( getApplicationContext().getCacheDir().getAbsolutePath() );
super.appView.getSettings().setAllowFileAccess( true );
super.appView.getSettings().setAppCacheEnabled( true );
super.appView.getSettings().setJavaScriptEnabled( true );
super.appView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT ); // load online by default

if (!isNetworkAvailable() ) { // loading offline
super.appView.getSettings().setCacheMode( WebSettings.LOAD_CACHE_ELSE_NETWORK );
}

super.loadUrl( "http://192.168.43.190/TA/index.php" );
}
private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( CONNECTIVITY_SERVICE );
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}
}

有没有人可以帮助我...?谢谢 :D

4

2 回答 2

0

如果您希望您的应用程序离线工作,请将您的数据存储到共享首选项中。

于 2013-09-07T03:48:24.527 回答
0

I don't have experience with Phonegap, and I can't tell what your exact problem is (Crashing? Nothing showing up? Formatting strangely?), but try

setContentView(webView);

if you want a new WebView to popup after loading the URL.

于 2013-09-07T02:07:33.263 回答