Unable to read internal storage file with html <a> on Webview - android

I am currently having problems referenceing a a file created into internal storage from my web view. the same code can reference similar file through href from a web address but when I decided to save the same file into internal storage I get Web Page at /data/data/packageName/files/fileName.html might be temporarily down.... any help would be appreciated
The line below resulted in an error when clicked on Webview:
<a href='/data/data/packageName/files/fileName.html'>
in fact when I tried with file:// the click was completely ignored as in <a href='/data/data/packageName/files/fileName.html'>
Meanwhile the same line works with <a href="http://www.someweb.co.uk/fileName.html'> is there any known workaround?

Related

How to get a local HTML to display a local image?

I'm trying to create a Delphi 11 app for Android 12, which opens a local HTML file with local images.
The local HTML file is stored here:
content://com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/MyFile.html
The local images are stored in the same local directory.
I can get Chrome and other browsers to open the HTML file without any problem, except that none of the images are displayed. Instead of my images the browser simply shows small icons with a broken corner, indicating an error.
None of these work for me:
<img src="mypic.jpg"/>
<img src="/storage/emulated/0/MyAppDir/Pics/mypic.jpg"/>
<img src="com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/mypic.jpg"/>
I just don't know what else to try after src=.
content://com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/MyFile.html
That is a content scheme uri.
You added a grand read permission to the intent so the browser could read the html source using the uri.
>><img src="mypic.jpg"/>
That is the src attribute that you should use.
Now the browser will try to read the image after having build an uri for it. The uri the browser build will be:
content://com.embarcadero.MyAppDir/fileprovider/external_public_files/MyAppDir/Pics/mypic.jpg
But unfortunately the browser has no read permission for this uri as you did not give it in the intent. (Not that it would be possible to do so).
Yes the old times were better. A browser just changed /path/file.html to /path/picture.jpg and all worked.

Image not loading on html file in android mobile

I'm trying to view my HTML file on the android mobile browser.
My HTML file has the following code:
<html>
<head>
<title>Testy</title>
</head>
<body>
<h1>Captain is Here</h1>
<img src='captain.jpg' width='30%' alt='Testy'/>
</body>
</html>
The image(captain.jpg) is also in the same folder where the HTML page is located. I'm getting the image on the computer browser but when I'm trying to open it in mobile browser image, not showing. I tried giving different file paths. How can I achieve this by giving a universal path by that a mobile that containing these HTML files should open in respective browsers and render images too?
1- your image size is too large try an image with a smaller size or resize or format your image into a smaller size.
try src-'./caption.jpg' instead of src='caption.jpg'
Opening through directry location of Html in Chrome Solve this.
For that get html file location directry in details by file manager
Example storage/emulated/0/web_folder/file.html and copy it
After that
1.Open chrome
2.type file:/// and Paste directry location
3."file:///storage/emulated/0/web_folder/file.html" Now it can run with image
Ensure that storage permission allowed to chrome
For that Open permission settings for chrome and allow storage permission
that's where mhtml and URLs get used!!!
Have you ever downloaded a page using chrome in android? if so you would have known about mhtml
MHTML, an initialism of "MIME encapsulation of aggregate HTML documents", is a web page archive format used to combine, in a single computer file, the HTML code and its companion resources (such as images, Flash animations, Java applets, and audio and video files) that are represented by external hyperlinks in the web page's HTML code
to convert your html to mhtml you may use some tools but you can also do it manually .
converting need not rename the file as index.mhtml but use all necessary files as hyperlinks
you may use image hosting sites like imgur or imgbb or even firebase if your familiar.
after you host get the link by
right-clicking image
open image in new tab
copy link
use it(link) instead of captain.jpg
Here is an example of how to get link using imgbb

Why can't I find a local file in my HTML?

I have the following really simple HTML - see below.
I have stored the HTML in a .html file on my PC and I have placed the PNG file in the same folder. When I open the HTML file, it works fine. However when I move the two files to my Android phone and execute the HTML file, the PNG file is not found (the not found icon is displayed). This happens with several browsers (including Chrome and Opera). This used to work. Any idea why I'm getting the error?
Has something changed recently? For example, when I open the above HTML file on my Android, I now see "content://" in the address line whereas I used to see "file://".
Many thanks
<BODY>
<IMG src="./1419196262_circle_close_delete-20.png">
</BODY>

Java android webview extract an iframe src http

I asked a question before but the wording was all wrong and I don't think it explained what I really wanted to do so here goes;
I have a webview in my app that access a website that I do not own or run, the website has a iframe with the following information:
iframe id="download_file" scrolling="no" src="http://www13.online-convert.com/download-file/41ffbb25dc972bdee4abc02ea1164fea/converted-df4a80e3.mp3">/iframe
Its a link that downloads a file, however the android webview doesn't allow me to click the link and download the file.
I have now added a button to my app, what I want the button to do is the following;
1 - extract the src http address from the iframe (http://www13.online-convert.com/download-file/41ffbb25dc972bdee4abc02ea1164fea/converted-df4a80e3.mp3)
2 - save that http address as a string that I can use.
3 - download the file.
The issue is I have know idea how to use javascript or a simple java code that can use my webview to locate that http address and save it as a string.
I have tried several tutorials, I have looked every where for a answer, is this even possible what I am trying to do?
Please any help would be great.
Try this;
Create a file in your assets folder named sample.html
<html>
<a href="http://www13.online-convert.com/download-file/41ffbb25dc972bdee4abc02ea1164fea/converted-df4a80e3.mp3" >Link<a/>
</html>
and your activity class onCreate function use this codes.
WebView webview;
webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/sample.html");

Accessing local files on android from epub files

I am trying to have an epub file link to an html document that is stored locally on my device.
I have an <a> tag with the href being:
"file://sdcard/mobi/content/file.html".
This does not work.
The epub file is currently located in the mobi directory as shown above, is there a way to relatively access the html file or is my href wrong?
I have tested the reader and it can open the file.html page if it is hosted on our local network.
Thank you in advance for any help

Categories

Resources