【问题标题】:How to save a complete webpage and load later for offline in DroidGap如何保存完整的网页并稍后在 DroidGap 中离线加载
【发布时间】:2013-06-07 06:36:37
【问题描述】:

我想制作一个可以在 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

【问题讨论】:

    标签: android caching cordova


    【解决方案1】:

    我没有使用 Phonegap 的经验,我不知道您的确切问题是什么(崩溃?没有任何显示?格式奇怪?),但请尝试

    setContentView(webView);
    

    如果您希望在加载 URL 后弹出一个新的 WebView。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-22
        • 2011-05-15
        • 2014-07-14
        • 1970-01-01
        • 1970-01-01
        • 2012-06-16
        • 1970-01-01
        相关资源
        最近更新 更多