Android URL方案从浏览器链接打开文件? [英] Android URL Scheme To Open File From Browser Link?

查看:513
本文介绍了Android URL方案从浏览器链接打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android(8.0)上,我正在尝试创建一个本地html文件,其中包含指向一些本地文件的链接,这些本地文件无法被Chrome直接查看,例如<a href="relative_path_to_file/file.docx">.在普通的网络浏览器(即在PC上)中,我可以单击该链接,它将在其默认查看器中打开文件.在Android上,如果我在Chrome中打开一个本地html文件,然后单击这些链接之一,它会将我定向到content://nextapp.fx.FileProvider/path_to_file/file.docx,显示找不到您的文件".我确实安装了适当的应用程序来查看文件(我可以通过文件资源管理器应用程序将其打开).我想了解如何构造URL,以便可以通过引用它们的链接来访问各种类型的文档(例如docx,xl​​sx,pdf等)-单击该链接应该可以打开文件,因为它从文件管理器访问文件时执行的操作.

  • 我尝试将链接重写为绝对路径,即"/storage/emulated/0/path/file.docx".结果是一样的.
  • 我尝试将链接重写为"file:///storage/emulated/0/path/file.docx". Chrome只是重定向到about:blank.
  • 我尝试使用"HTML Viewer"而不是Chrome打开html文档.行为大致相同(在第一种情况下,它重定向到about:blank,在第二种情况下说没有可用的应用程序打开链接.")

如何构造链接,以便可以单击和链接?在适当的查看器中打开引用的文件?

解决方案

最后弄清楚了.在其默认查看器中打开本地文件的有效链接如下:

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

...有一个重要的警告:如果路径中有任何点",它就会中断(即,我在.hiddenFolder中保存了文件,这显然导致Chrome无法弄清意图链接)./p>

参考: https://developer.chrome.com/multidevice/android/intents

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?

解决方案

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

这篇关于Android URL方案从浏览器链接打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆