I want to link to a local file in my Android device from my app. It can be by just opening it with file:// from the browser. Is this possible in Android, if so what is the path I need to put, just trying file:// does not show anything in the chrome browser.
5 Answers
Is this possible in Android
That will depend upon the browser.
if so what is the path I need to put
You can use a file://
URL pointing to a world-readable file.
just trying file:// does not show anything in the chrome browser
You would need to follow the file://
with the path to the world-readable file. Since your Web site probably has no idea what this path is, I have no clue how you expect to set up this link.
But, for example, suppose that your device has external storage located at /mnt/sdcard/
, and you have a file in there named foo.txt
, you could enter file:///mnt/sdcard/foo.txt
to display it in Chrome.

- 986,068
- 189
- 2,389
- 2,491
-
2Interestingly enough, Chrome displayed an [ERR_ACCESS_DENIED](http://android.stackexchange.com/q/57839 "Error code (ERR_ACCESS_DENIED) Local HTML file on SD card with Chrome") when trying to display ```file:///mnt/sdcard/Download/foo.txt``` - but _allowed_ the access to ```file:///mnt/sdcard/foo.txt```. In that file I (temporarily) kept my Google account password and after setting up the account (and a reboot), I could not reproduce this any more o_O – ckujau Mar 25 '17 at 21:11
Files which I downloaded from Yahoo mail were stored in /storage/emulated/0/Download. I confirmed this with termux. Files in this directory can be referred to as file:///storage/emulated/0/Download/file.ext or as file:///sdcard/Download/file.ext by the chrome browser. Neither of these URLs work with the Firefox browser (version 61.0). Firefox seems as though it is designed to access downloads via Tools | Downloads but perhaps only files downloaded by the browser. Back to chrome, more generally I can go to file:///sdcard and see a number of files and directories. As an alternative, you could get around the file permissions problems by setting up a webserver. If you are a programmer, one way to do this is by installing node.js (and termux) and writing an HTTP server using express. This would be addressed of course as http://localhost:8080/file.ext , assuming that it is configured to listen to port 8080.

- 21
- 3
file:///path/to/foo.txt
would give you the url path to the file. Make sure the file is world readable.
If you are trying to access file within your app, make sure you have the permission READ_EXTERNAL_STORAGE
. Above API version 23, you must explicitly request the user for storage permission. This link details on how to do it.
Another popular path would be
/storage/emulated/0/
So the path to an index file inside the Downloads directory would be
file:///storage/emulated/0/Downloads/index.html
How can one determine the local path easily? Open a locally stored image with the default image viewer, select image details in the context menu. This will include the absolute path on your given system.

- 2,464
- 23
- 32