【发布时间】:2015-02-04 18:11:29
【问题描述】:
我无法让我的应用程序在移动设备上注册 epub 文件。我的 android 清单中有一组意图过滤器,但它仍然无法使用 sd 卡上的 epub 文件打开。当我浏览File Explorer 应用程序时,它会显示该文件,但是当我单击它时,它会显示“系统不支持这种类型的文件:”。当我从 Internet 下载文件,然后使用下载应用程序导航到下载文件夹时,该文件根本不显示(即使它位于文件浏览器的下载文件夹中)。我还尝试让 epub 文件显示文件选择器意图 (Intent.ACTION_OPEN_DOCUMENT),但没有运气。我猜最后两个没有出现,因为意图加载了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>
更新:
为赏金寻找以下问题的答案:
- 如何让 android 系统识别可以使用我的应用打开内部或外部存储上的 epub 文件?
- 如何让默认文件浏览器 (Storage Access Framework) 显示 epub 文件?
【问题讨论】:
-
第一个
intent-filter(没有检查其他)在 Nexus 5(Android 5.0)上运行良好。愚蠢的问题,但是您确定要在活动标签中定义过滤器吗? :) -
看看这个,一定有帮助:stackoverflow.com/questions/3760276/…
-
@ozbek,是的,该应用程序只有一个活动,这些活动都在其中。感谢您的检查!
-
@ozbek,你说它适用于 Nexus 5?你能解释一下你打开文件做了什么吗?
-
简单地创建了一个示例应用程序,其中包含第一个意图过滤器和一个在目标内部 SD 卡中扩展名为
.epub的空文件。然后尝试使用OI File Manager 打开文件。系统显示“打开方式...”对话框,其中测试应用程序也被列为选项。
标签: android android-intent epub file-association