I have a task that sounds simple, but I have not yet figured out how to do it. I have a URL in my Android App. Now I want to download it, save it on my device, and then load it into a webview (let's say it is an image). I have to load my file from the device itself, so I cannot just load my image into my webview.
And the image has to be stored permanently. So that I can reopen it after closing the app even without internet connection.
I know how to work with Assets, but I cannot store files there that I am downloading during runtime, if I got this right.
If you are saving file in an html format on sd card you can load it in web view as shown below
webView.loadUrl("file://"+Environment.getExternalStorageDirectory()+"/filename.html");
Related
can i embed webpages in my app?
I need to view certain webpages of my company that is save to the app.
My app needs to access certain webpages in my company
Sure. Just add a WebView to your layout and have it load the html from a file locally (either on disk or in assets). This is assuming you don't want to download updates- if you do you need to cache the files locally then load them in the WebView.
One possible solution is to use a Service to download the pages when a connection is detected and cache them as local files on the device.
I would like to load a html file (with pictures and videos) on a Android tablet, however, there is no internet connection, thus I cannot use url for the pictures and stuff....
Is there any free web servers that allow me to do so (displaying the web content at local host)?
Or is there any way I can do it by writing a android app for it?
Thanks!!
Webview's LoadURL method can take local content. using the file uri retrieving the content from your assets and render it that way. Assuming you follow the standard folder structure for a basic HTML website.
And why would you want to ask about "free web servers" if you don't even have a internet connection... All the content has to be loaded locally on the app or downloaded on the fly (assuming you don't download too much.. if its too much then you are better off packaging it in the app).
Without Internet your html page is static page.
You can store the html file in your local assets folder then:
url = "file:///android_asset/" + mName + ".html";
mWebView.loadUrl(url);
and if you also want to show the images in your web page change the source path of images in source code of html page to local folder and pate all the images to that folder.
I am developing an Android application in which I have a WebView. I want to save the entire webpage loaded in this webview (Html + all resources + images + icons etc) into a folder and zip it and upload it to a server.
If you use WebView's saveWebArchive, then it is saved in archive format. How do I get the Html and images back from this archive? Is there any documentation for the format of this archive?
If I use addJavaScriptInterface to get the html as described here, I still have to copy the images and other resources from the webview cache dir (/data/data/your app package/cache/webviewCache/). However I did not find webview cache dir (/data/data/your app package/cache/webviewCache/) in Icecream Sandwich.
Is there a way to save the entire webpage displayed in webview along with resources in Android?
Thanks
If anyone is still interested, there is an open source project here that can read WebView's archive format (saved with saveWebArchive) and display it back in a WebView.
https://github.com/gregko/WebArchiveReader
I couldn't find details of the actual format yet.
You can use HTML 5 to store pages in the cache and load from the cache itself.
Caching is easy using HTML5, all you have to do is to make and refer a manifest file that holds information on what all elements need to be cached.
http://www.html5rocks.com/en/tutorials/appcache/beginner/
And here is a good way to implement the cache feature in your webview. http://alex.tapmania.org/2010/11/html5-cache-android-webview.html
Aman Gautam
I am downloading PDF file in my application and want to allow user to view it. Is it possible that using webview I can display that pdf file downloaded to SD Card or local memory.
As I know there is workaround in which I can provide the link of pdf file to google url which will open pdf in webview. But it lags and is very slow.
Basic answer, no. You can't open a PDF in a webview; so you either need to fire an Intent to open the file (the file can then open in the default installed app on the device); or write your own PDF reader.
Try to use pdf.js.
See http://www.worldwidewhat.net/2011/08/render-pdf-files-with-html5/
I downloaded its source and placed it in sdcard.
Then I use a WebView to load its index.htm.
It did show pdf file on a webView in sdcard in Android 4.0 device but sometime it show white page. I need to reload it and it finally can show.
Unfortunately, I also tested on Android 2.2 and 2.3 devices. They just show white page, nothing.
I know it make use of html5 canvas technology. I have checked on loading http://html5test.com/ on WebView and have tick on canvas element but still can't show pdf. Strange behaviour. Maybe really depends on Android version.
So on my android app, it uses webview to connect to my website and display the index.php file that is on there. That file takes images from a directory on my website and displays them. The problem is that it takes forever for the images to download onto the app! Is there a way I could get the images pre-loaded into the application so that it still runs the PHP like it is supposed to but it doesn't download the images from my website? The images would have the same name and everything. Think of it as having the images cached before downloading them. Is there anyway to do that?