Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving webpage in cache using webview in android

Tags:

I am working on an application where I load few websites in webview now I want to save webpages so after sometime even if there is not internet user will able to see those pages. But I am confused on how to save whole webpage in cache or any other medium. The main thing is we need to show pages back even if there is not internet. Has anyone implemented this before. Please provide some demo code as this is my first attempt on cache..

Thank You

like image 291
Sandip Jadhav Avatar asked Dec 07 '11 05:12

Sandip Jadhav


People also ask

How do I cache WebView?

This example demonstrate about How to enable app cache for webview in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do you store cache on android?

Open Settings and select Storage. In the resulting list, tap the Apps entry (Other Apps on Android 11 and earlier). This will take you to a list of all the apps installed on your phone. Choose the app whose cache you want to clear.

Where is WebView cache stored?

webview cache is saved into /data/data/[your_package_name]/cache/org.

What is alternative of WebView in android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.


1 Answers

The easiest way is save webpages in cache directory or any other(Internal or external storage)

You can get the data of web page using HttpClient.execute() or HttpClient.get() now store that data in .html file also you have to download images or other contents which are bind to that page, Now in your application you have to check for connection if connection not available then load the page which one you saved in storage with file://<location of your webpage..>

EDIT:

I think using HTML5 you can display off-line webpages. (I never tried this, but I referred some blogs on it). Look at this nice post about HTML5 Creating mobile Web applications with HTML 5, Part 3: Make mobile Web applications work offline with HTML 5 Also this

hope this will help you.

like image 87
user370305 Avatar answered Oct 20 '22 18:10

user370305