我无法让我的应用程序在移动设备上注册 epub 文件。我的 android 清单中有一组意图过滤器,但它仍然无法使用 sd 卡上的 epub 文件打开。当我经过File Explorer
应用程序,它显示该文件,但是当我单击它时,它显示“系统不支持这种类型的文件:”。当我从互联网下载文件,然后使用下载应用程序导航到下载文件夹时,该文件根本不显示(即使它位于文件浏览器的下载文件夹中)。我还尝试让 epub 文件与文件选择器意图一起显示(Intent.ACTION_OPEN_DOCUMENT
),但没有运气。我猜最后两个不会出现,因为意图加载Intent.CATEGORY_OPENABLE
我尝试了多个 epub 文件,但都没有成功。
有人可以帮我弄清楚我缺少什么吗?
使用 KitKat 及更高版本的手机。
注:这个does从互联网上下载。如果我转到 epub 链接,这可以工作,但不能从文件系统进行。
<!-- Open File Types -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:host="*" android:scheme="file"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:host="*" android:scheme="file" android:mimeType="text/plain"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="file"/>
<data android:mimeType="application/epub+zip"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="http"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="http" android:mimeType="text/plain"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="http"/>
<data android:mimeType="application/epub+zip"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="https"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="https" android:mimeType="text/plain"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="https"/>
<data android:mimeType="application/epub+zip"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="content"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="content" android:mimeType="text/plain"/>
<data android:pathPattern=".*\\.epub"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="content"/>
<data android:mimeType="application/epub+zip"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="*" android:scheme="book"/>
</intent-filter>
<intent-filter
android:icon="@raw/icon"
android:label="ePub File"
android:priority="1" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="ftp" />
<data android:scheme="file" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.epub" />
</intent-filter>
Update:
寻找以下赏金问题的答案:
- 如何让 Android 系统识别内部或外部存储上的 epub 文件可以用我的应用程序打开?
- 如何获取默认文件浏览器(存储访问框架 https://developer.android.com/guide/topics/providers/document-provider.html) 显示 epub 文件?
如何让 Android 系统识别内部或外部存储上的 epub 文件可以用我的应用程序打开?
“安卓系统”与它没有太大关系,尤其是在今天。
支持于MimeTypeMap
(或者,更准确地说,libcore.net.MimeUtils
来自框架类).epub
/application/epub+zip
was 约 35 小时前添加 https://android.googlesource.com/platform/libcore/+/7da22a29061da1553687258af71373417f2ae196。据推测,它会出现在 Android 的未来版本中。在此之前,唯一使用该 MIME 类型的文件管理器是那些本身添加了该类型的文件管理器。
从较高的层面来看,当遇到这样的问题时,解决方案相当简单:
找到另一个可以执行您想要的操作的应用程序(在本例中为另一个 EPUB 阅读器)
Use 应用程序浏览器应用程序 https://play.google.com/store/apps/details?id=com.japanesecrackers.appbrowser查看该应用程序的清单以及它选择的用途<intent-filter>
stanzas
一般来说,我通常会看到一个<intent-filter>
具有方案和 MIME 类型or方案、主机和路径的东西。具有 MIME 类型and路径的东西不太可能有帮助,就好像Intent
没有明确地包含 MIME 类型,并且 Android 不知道将该特定扩展名映射到您的 MIME 类型,您的<intent-filter>
可能不匹配。
此外,您还需要使用多个“文件管理器”应用程序进行测试,因为 Android 没有文件管理器,因此您可能会在正在测试的应用程序中遇到错误/限制。
如何让默认文件浏览器(存储访问框架)显示 epub 文件?
指定正确的 MIME 类型并祈祷奇迹出现。
再次强调,直到 Android 本身提供更多内置的映射支持.epub
对于 MIME 类型,您依赖于存储提供商本身恰好知道.epub
映射到application/epub+zip
MIME 类型。一些提供商会这样做,因为他们从某些后端服务器获取信息,这些服务器可能比 Android 本身知道更多的 MIME 类型。有些提供商可能不会,例如 Android 的MediaStore
-支持外部存储内容的提供商,因为我对此表示怀疑MediaStore
对 EPUB 文件有自己的本地支持。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)