I considered it a no-brainer. I was wrong.
I wanted to take along some files to read when I'm out of network reach or in flight mode. The files happen to be quite plain HTML files, no script, just a CSS file defining the simple layout, and that's it. So I copied the HTML and the CSS files onto my phone and tried to open them.
First attempt was from a file manager. It told me that it no idea what to do with an HTML file. I then tried to look for an "open file" entry in Chrome. Nope. Same in Firefox. Then I tried to force-open the files by using a file:///path/to/file style URL - and it actually submitted the whole string to Google as a search string, as if Chrome (and Firefox) had been lobotomized of the file: protocol.
Now I'm at a loss - is there no way to open a simple HTML file on an Android 13 phone?
Videos
For the sake of those who might be on a similar situation, there is a MUCH BETTER approach to run your html + js + css apps on mobile devices.
You just need to convert them to Proggressive Web Applications (PWA), this means just to tweak them lightly and add a manifest file. Those apps CAN be INSTALLED on mobile devices directly from browsers, working as native apps.
You can find info about this topic in https://web.dev/explore/progressive-web-apps?hl=es-419
You placed your files in a suitable folder.
The problem is that you used a content scheme uri that also hides real file names.
content://media/external/file/123456
points to your html file. If the browser has to display a picture like image.jpg it will build an uri like content://media/external/file/image.jpg.
But that is no valid uri as this provider uses digits like you told us. And even if the url was ok you would not have read permission for it.
You have 2 options:
You can use a local web server in your Android phone itself. There are many server apps out there in the Play Store, one such app is Simple HTTP Server.
You can put your documents into the folder
Android/data/com.android.chrome/files/Download/in the internal storage. It's absolute path is/storage/emulated/0/Android/data/com.android.chrome/files/Download/or/sdcard/Android/data/com.android.chrome/files/Download/. This is the location where Chrome stores any downloaded files and therefore, this the only location where Chrome can access the files. But remember, uninstalling Chrome will delete this directory.
For Android 11 [One UI 3.1]
Browsing local files (in internal storage space) in Chrome using file:///sdcard/ or file://localhost/sdcard/, one can notice that only media files and subdirectories (if any) are listed in almost every folder except the "Download" folder (but not in its subfolders=subdirs).
This means that on Android 11, the folder from which Chrome can read local (m)HTML is /Download folder, not Android/data/com.android.chrome/files/Download in internal or external storage space like in Android 10.
NOTE: on my Samsung devices, downloads onto internal storage were saved into /Download folder in all versions of Android (9, 10, 11), but downloads on an external SD card changed their folder from /storage/emulated/exSD_CARD/Android/data/com.android.chrome/files/Download in Android 10 to /storage/emulated/exSD_CARD/Download in Android 11, where exSD_CARD is the device's label for external SD card (0123-4567 or 9C33-6BBD in my devices)
Thus, (m)HTML files saved into /Download folder with Chrome (with .mhtml extension from older times or with manually added extension by renaming saved mhtml files without extension - from certain time Chrome stopped to append .mhtml extension to saved mhtml files :) on my devices, I guess from upgrading to Android 10)
This did not work for the mhtml files which have been moved to other folders and then returned to /Download folder. (And because of collecting saved mhtml files in many different folders, I have many mhtml files which are necessary to copy/move back to /Download folder prior to opening but they still cannot be opened)
Notes about opening mhtml files
I need to use Total Commander's "Open with" functionality with file://url option checked, then choose Chrome in order to open (mhtml) file with Chrome (with file://url checked, the Chrome is in the list to choose from, with file://url option unchecked, it is not listed in the list) or to browse local files in internal storage directly in Chrome (file manager My Files provided with the device was unusable to choose mhtml files to be opened with Chrome)
(mhtml) files from /Download folder opened in this way are opened as offline versions of downloaded web pages - but only if the file was not moved and returned back to /Download folder, otherwise you get Access Denied message. Also, opening (mhtml) files in this way using Total Commander, but from other folders than /Download folder, leads to Access Denied message
Opening mhtml files from any folder using Total Commander, but with file://url option unchecked (in this case, the Chrome is not in 1st list, so you need to choose "Open with *" option with folder icon from the list and subsequently choose Chrome from next list) behaves differently. Opening in such a way leads not to successful opening or Access Denied message but to Save as Dialog Form in which one can choose also if the resaved mhtml file should be saved to internal storage or external SD card (if present). In this way, resaved mhtml files in /Download folder (on internal or external storage space) can be now opened using Total Commander "Open with" dialog with checked file://url option.
Still, there exists a way of opening the (m)HTML files with Chrome
- without other browsers/viewer
- without rooting the Android device
but maybe only until the next update :)
Just tested it on my phone with a simple html file (text, link, image).
And it should be enough if you just navigate to that .html file in your Android file manager and open it with the browser of your choice.
- Navigate to .html file using Android built in file manager
- Long press on the file until it is show as selected
- On your top bar, press the three dots
⋮ - In the menu that opens, press "open with"
- Now you can select which app you want to choose to open the file, select any browser
Afterwards your browser should open and display the rendered website, including images, styles etc. as long as they are at the correct place like defined in your .html file.
You'd need to rewrite all URLs, else this will result in HTTP 404...
another option would be to base64 encode and inline all the images.
You should be able to point the browser at the file you want with a URL of the format file:///path/to/file.html. For example, I just did this on my EVO with a file I saved to the root of my SD card as post.html by launching the browser and entering the URL file:///sdcard/post.html.
Alternatively, my file manager lets me open an HTML file with "HTML Viewer". This is not as feature-rich, though, and didn't seem to render images for me (whereas the browser way loaded everything properly). My file manager does not give me the option to open the file with the browser, or either of the other browsers I have (Firefox and Opera Mobile).
Just type file://localhost/
It works in Opera Mobile.
You can use a local server to host the webpage, and navigate to the private IP of your pc from your mobile device if they are connected to the same network.
I prefer live-server npm package for this. Simply type npm install -g live-server. Navigate to the directory your website is located at then run live-server. It will also show the port you are running on.
To find out your private ip address, open another command line and type ifconfig (or ipconfigif you are on windows).
Navigate to ip-address:port-number in your mobile device and you will see your website. Example private ip address and port number: 192.168.1.40:8080
The easiest way for previewing on the mobile device is using websites such as : https://search.google.com/test/mobile-friendly? I hope this helps you to determine your problem.