I want to save the webpages in sdcard when it loading in custom WebView and next time loading the same url I want to load it from cache and updates in the webpage should save in the cache.
Please try to use Asynchtask and download html file ,code right into doBackground method and set html in onPostExicute method.
Related
I have created a library to start an activity with a Webview.
I'm trying to load local HTML file which with an Iframe inside it Whenever I'm starting the activity, for first time it is taking approx. of 5 seconds to display iframe. The 2nd time it is taking approx. of 2 seconds to display.
How can i reduce load time, for the first load?
Here are the two java files respectively.
WebviewOverlay.java
String botUrl = "someurl";
myWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
myWebView.loadUrl(botUrl);
return myWebView;
WebviewActivity.java
wb = new WebviewOverlay();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().add(R.id.container, wb).commit();
This one is not anything to do with Android, web page has lot of data and or may be high resolution images which taking time or any scripts on the page which taking time while loading
You can use precaching to speed up the webpage load.
Load data(HTML) from the server and save it to a text file in our device memory.
Start a coroutine to load the webpage and store in local storage
Create a new activity in which we will create a webview which will be used to load this cached webpage.
Change some settings of our webview to enable support for javascript, domstorage, database etc.
Attach webclient to our webview
Load our previously created file which contains all our HTML cached and load it to the webview
Here's a Github repo that does exactly what you want it to do.
https://github.com/iambaljeet/WebViewPreCache
Try using optimized images in your Webpage. Resize it from mspaint
I am developing story feature app like instagram or whatsapp but I got stuck somewhere. I am getting image thumbnail from server as URL but when I try to use it . It take some time to load that image.So I want to Load add thumbnail images from url in previous activity and then set that thumbnail from cache.How I can store url images in cache Hashmap or arraylist to use them in next activity.Please help.I am in trouble right now.
You can use Glide for catching the image from URL.
i load a web page in a webview that contains a form, i want to know if there is a way to save the data that user put in the form in the webview cache and auto fill it in his next visit?
this is all i have done for now.
webView.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache");
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
not sure if it's the right way but, what about running js script on webview to get form input values, navigating DOM tree of html or using selector with id ?
once you got them you can store them in your app and for repopulate, before loading the page in webview, you manipulate html (if you could) or you use another js script to set the values
i'm not sure but i thing cache is only for cachable values (images, css...) not for input
Here is my coding
webView1.loadUrl("http://www.ppshein.com.mm/testimage.jpg");
What I want is I want to cache this image when image is completely loaded in webview. That's why it can be able to display when device is offline.
Add the next lines:
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
you can open cacheMode.when your img downloaded,it will be in the/data/data/your packagename/cache the directories below
When I try to reload the titanium webview true webview.reload(), the view does not reload correctly. Instead if loading the page it gives me a page not found.
what i'm doing:
In Titanium i make use of webviews to display data. These webviews make use of HTML that is stored in the local filesystem that Titanium offers. The webview is called url is set by :
webview.setUrl( Ti.Filesystem.applicationDataDirectory.toString() + 'index.html');
This sets the proper url for the webview, it let's me see the correct html page. When I use webview.reload(), it seems lost... is there a way to reload the webview, or should i remove and then add the webview again?
Setting a URL for WebView the resource is usually loaded from the Resources folder.
So try to move all HTML files there (into Resources, same folder where app.js is located) and simply use.
webview.setUrl('index.html');
This has worked for me both on iOS and Android.
(There is an issue related to Android regarding WebView and setting its content by html property but this shouldn't matter here)