Open image inside WebView in new Activity on clicking - android

Is there a simple way to open an image in new Activity on clicking it inside the webview?
Or It would be great if I can get the full url of the image on clicking it inside the webview.

Not possible, because how should you get the image url ?
it is difficult to get return values from webview events outside the context of webview.
if you have the direct URL of image then you can easily rendered it on UI but without direct URL you can't render an image.

Create an HTML file
<html>
<img src="abc.jpeg" width="100px" >
</html>
put it in an assests folder of your android application and load the html in your webview
webview.loadUrl("file:///android_asset/abc.html");
You can store the image in the assets folder along with the html
page, and specify the image name as the value of src in img tag
in html code,
or you can give the public URL of the image and the image will be
renderd on its own

Related

Use drawable inside HTML Page

I am developing an application in which I am loading an HTML page inside Webview. I am to use an image in that HTML which is inside my drawable. How would I give path to that image inside HTML.

Displaying a image captured using Camera inside an html image tag placed within a WebView - Xamarin.Android

I'm looking for a way on to display the image captured using Camera2 API in Xamarin.Android inside an HTML tag which is placed within a WebView.
Though it was possible to obtain the File URi where the image is located, setting it into the image tag which I have tried, isn't working. I also want to know whether this kind of thing can be done in Native Android.
You can encode the content of the image in base64, and than set it in the src of your img tag like this:
<img src="data:image/jpg;base64,VeryLongBase64EncodedImageData"/>

Can i center external content in a WebView?

I am loading an image from external url directly in a WebView. So now i want to center that image. I can't edit the file to add css or js. Is it possible and when it is, how?

Missing image on html file in android default web browser

I have a html file (contains some text and one image) stored # /sdcard/test folder.
And image is also stored under same folder. I'am able to see the image on html file if i open html file programmatically (using a WebView).
((WebView)findViewById(R.id.webView)).loadUrl("file:///mnt/sdcard/test/report_external.html");
It works. But when i go to that folder and open that html file (using default web browser of android), image file is not getting displayed. It is showing everything except image. What is the problem with default android browser to view the html file? Are there any differences between opening the file using defalut browser & WebView?
Here is my image tag in html
<img src = "file:///mnt/sdcard/test/image.png"></img>
How could i see the image on html if it opened with default browser also?
I think there's something wrong with your img-path. Try to set src="image.png", it should work when both files are in the same directory. Let me know if it works.
Change the name of the image to something else and try. might work.
try file:///sdcard/test/report_external.html
instead of file:///mnt/sdcard/test/report_external.html
That's remove /mnt in your path, does it work now?

Radio button styles not showing in webview

I designed some radio buttons with images using css, because I want to make the radio button look bigger.
Now, when I load it in browsers it works fine, same in mobile browsers. But when I try to load it in webview the radio button is not visible. Is there anyway to enable css?
You don't need to enable css. You just link to it from you html file like you normally would
Put the html, css and image resource files in the assets folder of your project and load the html using "file:///android_asset/yourwebpage.html" as a Url.
if your css file is separate then you need to provide complete relative path in html page you include the html page like file:/// something like that.
mobile brower can take relative path by itself like say your accessing from wampserver but if you are putting all in webview and loading then it dont take relative path by itself. By the way where you are putting all this files in assests or sdcard ?

Categories

Resources