android - 将 App 与 Epub 格式相关联

标签 android android-intent epub file-association

我无法让我的应用程序在移动设备上注册 epub 文件。我的 android list 中有一组 Intent 过滤器,但它仍然无法使用 sd 卡上的 epub 文件打开。当我浏览 File Explorer 应用程序时,它会显示该文件,但是当我单击它时,它会显示“系统不支持这种类型的文件:”。当我从 Internet 下载文件,然后使用下载应用程序导航到下载文件夹时,该文件根本不显示(即使它位于文件浏览器的下载文件夹中)。我还尝试让 epub 文件显示文件选择器 Intent (Intent.ACTION_OPEN_DOCUMENT),但没有运气。我猜最后两个没有显示,因为 Intent 加载 Intent.CATEGORY_OPENABLE

我尝试了多个 epub 文件,但都没有成功。

有人可以帮我弄清楚我错过了什么吗?

使用 KitKat 和更高版本的手机。

注意:这确实适用于从互联网下载。如果我转到 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>

更新:

为赏金寻找以下问题的答案:

  1. 如何让 android 系统识别可以使用我的应用打开内部或外部存储上的 epub 文件?
  2. 如何让默认文件浏览器 (Storage Access Framework) 显示 epub 文件?

最佳答案

How do I get android system to recognize that epub files on internal or external storage can be opened with my app?

“android 系统”与它没有太大关系,尤其是在今天。

支持 MimeTypeMap (或更准确地说,来自框架类的 libcore.net.MimeUtils)对于 .epub/application/epub+zipadded ~35 hours ago .据推测,它将出现在未来的 Android 版本中。在此之前,唯一会使用该 MIME 类型的文件管理器是那些自己添加它的文件管理器。

在高层次上,当遇到这样的问题时,解决方案相当简单:

  1. 找到另一个可以满足您需求的应用(在本例中,是另一个 EPUB 阅读器)

  2. 使用the App Browser app查看该应用程序的 list 是什么样的以及它为<intent-filter> 选择了什么节

一般来说,我通常会看到 <intent-filter>带有方案和 MIME 类型方案、主机和路径的东西。拥有 MIME 类型 路径的东西不太可能有帮助,好像 Intent没有明确的 MIME 类型,Android 不知道将特定扩展名映射到您的 MIME 类型,您的 <intent-filter>。可能不匹配。

此外,您将需要使用多个“文件管理器”应用进行测试,因为 Android 没有文件管理器,因此您可能会在您正在测试的应用中遇到错误/限制。

How do I get the default file browser (Storage Access Framework) to show epub files?

指定正确的 MIME 类型并祈求奇迹。

同样,直到 Android 本身提供更多的内置映射支持 .epub对于 MIME 类型,您依赖存储提供商自己碰巧知道 .epub映射到 application/epub+zip MIME 类型。一些提供商会这样做,因为他们从某个后端服务器获取这些信息,这些服务器可能比 Android 本身了解更多的 MIME 类型。有些供应商可能不会,例如 Android 的 MediaStore - 支持外部存储内容的提供商,因为我怀疑 MediaStore对 EPUB 文件有自己的本地支持。

关于android - 将 App 与 Epub 格式相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27335114/

相关文章:

javascript - 获取所有不是 span 的元素

Android - SimpleCursorAdapter.ViewBinder - 设置背景颜色

android - 如何克服此错误 :java. lang.OutOfMemoryError:位图大小超出 VM 预算

java - 在Android中创建文件夹解压epub

xml - 如何使用 PowerShell 提取 Epub 元数据 (XML)?

java - onActivityResult 在 API 级别 17 下未调用

android - 任何用于在 Eclipse 上的 Android 中裁剪图像的好库

android - 重绘后 ListView 消失

android - Instant Apps : "You should have at least one active APK that is mapped to site ' sample. com' via a web 'intent-filter' "当推送到生产环境时

android - Activity Intent 完成后运行代码