Load images or whole site from local "assets" folder using webview - android

The question I have is simple but hard to put in words, I'll give it a try anyways.
I am trying to load a web page in webview. However, the load time is a little bit too high.
Is there any way I can put the images in the assets folder and load them from there instead?
If not, is there a way I can load the whole site from the assets folder, providing that my PHP files can still communicate with my internet database?
I have already read most tutorials, but those are pretty vague when it comes to concrete help.

try this... WebView with custom HTML and local images

There is no way to store your php files on the device itself. They need a server to execute them and sent the result to the device if the are on the device you would just show the php code to your webview and that would certainly not work.
The Webview should be able to cache some of the images itself. But it seems that there is no way to access images from the sd card or the internal storage from your webview.
Maybe it is possible to store some of your data through html5 local storage apis but I don't have any expertise on that.

Sure ! you can do it. Just install AndroPhp it is a localServer for Android.
Locate you project than on your device under the www/ folder. If you have a DB also just import your .sql trough phpmyadmin.
on Android side call you project 127.0.0.1:8080/yourProject
Thats All!

Related

displaying pdf in xamarin android

I am trying to create an app that will be able to display a pdf file in the app itself. I'm currently using the Xamarin.Bindings.PDFView-Android by SIDOVSKY which works really nicely. I can open a file easily from the assets... what I'm struggling to do is open a file from the internet.
Just a single line of code:
FindViewById<PDFView>(Resource.Id.pdf_view).FromAsset("report.pdf").Show();
Is enough to display a PDF that can be pinched to zoom which is great. However, I now want to access a file stored on the local network. Either using a SMB share, or through the intranet. Whichever way I try I can't figure it out.
There is a .FromFile setting, but I can't get it to work by putting a smb path in here. Is there a way to convert this? Or must I download the file to the local device first?
Thanks
Andrew

Update offline webpages without updating app

I have an app which contains html files which i am displaying using a webview. This html files are nothing but documentation the users of my app require. My question is, can I update these html files without asking the user to update the entire app? I dont want to replace these html files by hosting the documentaion online.
You will have to do one of these:
Update your app (which is what you don't want)
Host the raw .html files on a web server, and whenever the user opens the app, check if there are new files available and download them.
Simply create a website that shows the .html files and open the
website in your app (which i'm guessing is what you don't want
either)
So you're left with option 2.
To update files without requiring an app update, you will need the app to obtain the HTML content online.
One option, which you mentioned you don't want, is loading a URL into the WebView rather than local HTML files.
The other option would involve hosting the web pages somewhere and the app would download them. The only benefit of this I can see, is that if the device is offline is can use the last obtained HTML file. You could just use caching to achieve this though.
How complicated are the webpages? Using JSON is another method.

How to view webpages offline

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.

How do I save a complete webpage displayed in Android's WebView?

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

Saving webpage in cache using webview in android

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
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.

Categories

Resources