Android HTML View - android

Using Android, I have a WebView. I create html locally which includes references to css, javascript and images in the Assets folder. This local html is then displayed.
How do I get the WebView to reference the Assets' javascript and images?
I am guessing I need to tell the HTML VIew that the base folder is the Assets folder? If so, how?

You should acces the file index.html using this location:
file:///android_asset/index.html

Related

How to add a particular CSS for particular app

I have a live website which I want to show in my app with WebView. But also I want to add a css file in my website which will only work if This particular app load the website. Otherwise that css will not work.
Is this possible? If possible please anyone can tell me how to do that?
Put your index.html of your Website and the css file in the assets folder of your Android project. Modify your index.html so it will load the css file by adding a link to it.
Then when loading the WebView, just load the index.html from your assets folder and you are done. Like so: webView.loadUrl("file:///android_asset/index.html")

android webview load html from server and other files from assets

im a new android developer.
My app has WebView which loads lot of data from my site (which has pics, css, JS files).only the html code is updated weekly. other files are almost never changed. so i was thinking of including these static files in android assets, loading only the html from server and other files from assets and cutting down the loading time. how do i do it.
Android WebView Javascript from assets
and as shown in the above solution i cant change the html code to load these from assets because this site will also be accessed by web users.
Is there a way to do this. Thanks in advance..
Firstly you need to have relative paths
<img src="images/someimage.png">
not
<img src="www.mysite.com/images/someimage.png">
Then you need to load the HTML code not using webBrowser, for example like here
And then you can load HTML source into WebBrowser using base URL pointing to your assets like here

Android Load Apart of url to webview

I want to load a part of Website to Webview. Not completed Website.
How can I do it?
It is similar this question.
Load a div into a webview on Android
But the answer only load text. not have Image.
Any one there?
1.Create a HTML file with a frame (or iframe) in it and save it in your assets folder.
2.Load your file in webview from assets .

Local files are innaccessible from an external url using PhoneGap on Android

<img src="file:///android_asset/www/images/image.png" style="border: black dashed 2px"/>
This line of code works as expected on a local html file.
However when you open an external url inside the app. (For example http://www.example.com/mobile/) The same line of code doesn't show an image.
To be clear, I am trying to access local files from an external url, because there are some JS files that are huge and It will be a waste of bandwidth to download them externally.
The remote site will never be able to load an image from the file:// protocol.
As #simon said u wont be able to load local assests on external url.. At best u can use loadDataWithBaseURL which will load your html with imgs/css/js from local assets folders
something like this
webView.loadDataWithBaseURL("file:///android_res/raw/", html,
"text/html", "UTF-8", null);

android load local path html and swf file using webview

i have a html embeds a swf file
i write this to load the html file by webview :
mywebview.loadUrl("file:///android_asset/myweb.html");
now i have a question , i wanna let the html embed a swf file , which also in the
eclipse project assets directory.
could anyone tell me what path should i set? file:///android_asset/myswf.swf??
You should use a relative path. If your HTML and SWF file resides in the same folder, use the SWF filename directly. (i.e. myswf.swf).

Categories

Resources