-1

i am building an RSS reader application in android via eclipse for my homework in my class.

i have a problem is: how to read RSS feeds while offline. it means that while online i can save some feeds for offline reading

can you help me or suggest me how to do that thanks very much

vuong phuong
  • 11
  • 1
  • 4

1 Answers1

0
WebView webView = new WebView( context );
webView.getSettings().setAppCacheMaxSize( 5 * 1024 * 1024 ); // 5MB 
webView.getSettings().setAppCachePath( getApplicationContext().getCacheDir().getAbsolutePath() );
webView.getSettings().setAllowFileAccess( true );
webView.getSettings().setAppCacheEnabled( true );
webView.getSettings().setJavaScriptEnabled( true );
webView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT ); // load online by default

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

webView.loadUrl( "http://your.feed.url" );  

This is how you will save the webpage offline. The isNetworkAvailable() looks like this:

private boolean isNetworkAvailable() { 
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( CONNECTIVITY_SERVICE );
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}   

Source: WebView load website when online, load local file when offline

Community
  • 1
  • 1
An SO User
  • 24,612
  • 35
  • 133
  • 221