1

On Android (8.0), I'm trying to create a local html file that includes links to some local files that can't be viewed directly by Chrome, like <a href="relative_path_to_file/file.docx">. In a normal web browser (i.e. on a PC), I can click the link and it will open the file in its default viewer. On Android, if I open one of the local html files in Chrome and click one of those links, it directs me to content://nextapp.fx.FileProvider/path_to_file/file.docx, showing "Your file was not found." I do have an appropriate app installed to view the file (I can open it via a file explorer app). I would like to understand how I can structure the URLs such that docs of various types (i.e. docx, xlsx, pdf, etc) can be accessed via the links that refer to them - clicking the link should offer to open the file, as it does when accessing the file from a file manager.

  • I tried rewriting the links to an absolute path, i.e. "/storage/emulated/0/path/file.docx." The result is the same.
  • I tried rewriting the links to "file:///storage/emulated/0/path/file.docx." Chrome just redirects to about:blank.
  • I tried opening the html doc with "HTML Viewer" rather than Chrome. The behavior is more or less the same (in the first case it redirects to about:blank, in the second it says "No app available to open link.")

How can I structure the link so it can be clicked & open the referred-to file in appropriate viewer?

J23
  • 3,061
  • 6
  • 41
  • 52
  • try this question to do https://stackoverflow.com/questions/10242306/android-how-to-open-a-doc-extension-file?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Hitesh Sarsava May 01 '18 at 04:52
  • Related (& I had read that answer previously), but I still couldn't figure out how to structure the url in html per my question (so it offers the available apps for that file type)... – J23 May 01 '18 at 06:23
  • have you read about interacting html in android in net? – Hitesh Sarsava May 01 '18 at 06:33
  • ...Huh? Are you asking if I've searched online for a solution? Yes, obviously...that's why I'm asking :P – J23 May 01 '18 at 08:02
  • How does Chrome on Android behave if it just displays the website and not uses the local files? – greenapps May 01 '18 at 08:48
  • Sorry, I clarified the question - it isn't actually an offline copy of a website that exists online; it's an html doc I'm creating from scratch, locally. So it's local-only. – J23 May 01 '18 at 09:44
  • Have you tried other browsers like firefox and opera? – greenapps May 01 '18 at 16:29
  • Edge behaves identically to Chrome. Firefox didn't appear as an "Open With" option (I guess it didn't identify itself as a handler for .html files), but if I explicitly did Open With in FX Explorer, it said access to the file was denied, I guess because it doesn't know how to request access to storage. Opera didn't appear as an "Open With" option, but if I explicitly Open With w/ FX, tapping the link will download the file to the /Download folder. – J23 May 01 '18 at 17:25

1 Answers1

1

Finally figured it out. A working link to open the local file in its default viewer looks like:

"intent:///abs/path/to/file.docx#Intent;scheme=file;action=android.intent.action.VIEW;end;"

...With one important caveat: it breaks if there are any "dots" in the path (i.e. I had the files in a .hiddenFolder, which apparently causes Chrome to be unable to figure out the intent link).

Reference: https://developer.chrome.com/multidevice/android/intents

J23
  • 3,061
  • 6
  • 41
  • 52