将应用程序与 Epub 格式关联 [英] Associating App with Epub format

查看:38
本文介绍了将应用程序与 Epub 格式关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm at a loss for getting my application to register with epub files on a mobile device. I have a set of intent filters in my android manifest, but it still will not open with epub files on the sd card. When I go through the File Explorer app, it shows the file, but when I click on it, it says "The system does not support this type of file:". When I download a file from the internet, and then navigate to the download folder using the downloads application, the file does not show up at all (even though it's in the download folder in the file browser). I've also tried to get epub files to show up with the file chooser intent (Intent.ACTION_OPEN_DOCUMENT), but no luck. I'm guessing the last two do not show up because the intent loads with Intent.CATEGORY_OPENABLE

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

I've tried multiple epub files and all without success.

有人能帮我弄清楚我遗漏了什么吗?

Can someone help figure out what I'm missing?

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

Using KitKat and higher phones.

注意:这确实适用于从互联网下载.如果我转到 epub 链接,这会起作用,但不能从文件系统中运行.

Note: this does work with downloading from the internet. If I go to an epub link, this works, but not from the filesystem.

        <!-- 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:

Looking for answers to the following questions for the bounty:

  1. 如何让 Android 系统识别出可以使用我的应用打开内部或外部存储中的 epub 文件?
  2. 如何让默认文件浏览器(存储访问框架)显示.epub 文件?
  1. How do I get android system to recognize that epub files on internal or external storage can be opened with my app?
  2. How do I get the default file browser (Storage Access Framework) to show epub files?

推荐答案

如何让 Android 系统识别出可以使用我的应用打开内部或外部存储中的 epub 文件?

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

安卓系统"与它没有太大关系,尤其是在今天.

The "android system" does not have much to do with it, particularly today.

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

Support in MimeTypeMap (or, more accurately, libcore.net.MimeUtils from the framework classes) for .epub/application/epub+zip was added ~35 hours ago. Presumably, it will show up in a future edition of Android. Prior to that, the only file managers that will use that MIME type are ones that added it in themselves.

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

At a high level, when confronted with a problem like this, the solution is fairly simple:

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

  1. Find another app that does what you want (in this case, another EPUB reader)

使用应用浏览器应用查看该应用的内容manifest 的外观以及它为

Use the App Browser app to see what that app's manifest looks like and what it chose for <intent-filter> stanzas

通常,我通常会看到带有方案和 MIME 类型的 方案、主机和路径内容.拥有 MIME 类型 路径的东西不太可能有帮助,好像 Intent 中没有明确包含 MIME 类型,而 Android 不知道映射那个您的 MIME 类型的特定扩展名,您的 可能不匹配.

In general, I usually see an <intent-filter> with a scheme and a MIME type or a scheme, host, and path stuff. Having the MIME type and the path stuff is unlikely to help, as if the Intent does not explicitly have the MIME type in it, and Android doesn't know about mapping that specific extension to your MIME type, your <intent-filter> may not match.

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

Also, you will need to test with multiple "File Manager" apps, as Android does not have a file manager, and therefore you may be experiencing bugs/limitations in the one that you are testing.

如何让默认文件浏览器(存储访问框架)显示 epub 文件?

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

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

Specify the proper MIME type and pray for a miracle.

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

Again, until Android itself offers a bit more built-in support for mapping .epub to the MIME type, you are reliant upon storage providers themselves happening to know that .epub maps to the application/epub+zip MIME type. Some providers will, because they are getting that information from some back-end server that may know more MIME types than does Android itself. Some providers may not, such as Android's MediaStore-backed provider of what's on external storage, as I doubt that MediaStore has its own local support for EPUB files.

这篇关于将应用程序与 Epub 格式关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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