Jas*_*son 21 android file-association epub android-intent
我无法让我的应用程序在移动设备上注册epub文件.我的android清单中有一组intent过滤器,但它仍然无法在sd卡上打开epub文件.当我浏览File Explorer应用程序时,它会显示该文件,但是当我点击它时,它会显示"系统不支持这种类型的文件:".当我从Internet下载文件,然后使用下载应用程序导航到下载文件夹时,该文件根本不显示(即使它位于文件浏览器的下载文件夹中).我也尝试使用文件选择器intent(Intent.ACTION_OPEN_DOCUMENT)来显示epub文件,但没有运气.我猜测最后两个没有显示,因为意图加载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>
Run Code Online (Sandbox Code Playgroud)
为赏金寻找以下问题的答案:
如何让android系统识别内部或外部存储上的epub文件可以用我的应用程序打开?
"android系统"与它没有太大关系,特别是今天.
在支持MimeTypeMap(或者,更准确地说,libcore.net.MimeUtils从框架的类),用于.epub/ application/epub+zip被〜35小时前添加.据推测,它将出现在未来的Android版本中.在此之前,将使用该MIME类型的唯一文件管理器是自己添加它的那些.
在高层次上,遇到这样的问题时,解决方案非常简单:
找到另一个做你想要的应用程序(在这种情况下,另一个EPUB阅读器)
使用App Browser应用程序查看该应用程序的清单是什么样的以及它为<intent-filter>节点选择了什么
通常,我通常会看到一个<intent-filter>带有方案和MIME类型或方案,主机和路径的东西.拥有MIME类型和路径内容不太可能有所帮助,就好像Intent它没有明确地包含MIME类型,并且Android不知道将该特定扩展名映射到您的MIME类型,您<intent-filter>可能不匹配.
此外,您需要使用多个"文件管理器"应用程序进行测试,因为Android没有文件管理器,因此您可能遇到了正在测试的错误/限制.
如何获取默认文件浏览器(存储访问框架)以显示epub文件?
指定正确的MIME类型并祈祷奇迹.
同样,在Android本身为映射.epub到MIME类型提供更多内置支持之前,您依赖于存储提供程序本身就知道.epub映射到application/epub+zipMIME类型.一些提供商会,因为他们从一些后端服务器获取该信息,这些服务器可能比Android本身知道更多的MIME类型.有些提供商可能没有,比如Android的MediaStore外部存储提供商,因为我怀疑它MediaStore有自己的EPUB文件本地支持.
| 归档时间: |
|
| 查看次数: |
1554 次 |
| 最近记录: |