i am trying to load local images in android webview by using assets folder, but when i tries to open it, it is loading only HTML but not images
In my HTML Code i have added following line
<IMG SRC="file:///android_asset/images/a.jpg">
But it is not displaying image, can anybody please help?
put your images into the Assets folders by creating separate images folder like assets/images and then in your html page provide path of your image as
<IMG src="images/test.png">
first of which url loading in webview, is it local url or http (means requires internet). If ur loading local file system url pealse check the image path properly, it should work. if loading http url trying load a local images inside it sorry its not possible. Here its cross domain issue will restrict to that.
Related
I'm creating an HTML file with css and java, and I want to load an image using img tag, but Android isn't loading the image when using img src="" code.
The image is the phone's Download folder of the Android phone, but I can't figure out the path I have use to load the image in the HTML.
I recommend you to upload the image to a server like google photos or github so that you can copy its url and assign it to the source atributte of the element.
Give it at try and tell me if you have any problem!
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
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 .
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.
<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);