【发布时间】:2017-02-22 16:28:02
【问题描述】:
我有一个经过检测的电子书阅读器应用程序,它可以通过两种不同的方式打开,一种方式是通过另一个应用程序直接从服务器下载内容,然后启动阅读器。另一种是从文件系统打开电子书。前者工作得很好。后者有效,[i]但仅适用于特定的文件管理器[/i]。它适用于 Astro 和 ES 文件管理器。它不适用于默认的 Android 文件管理器或 AndExplorer(这显然不是详尽的测试)。
这是清单中的相关部分:
<activity
android:name=".activities.IntentResolverActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="stateHidden|adjustPan"
android:theme="@android:style/Theme.Holo.Light.NoActionBar"
android:exported="true"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.epub" />
<data android:mimeType="*/*"/>
</intent-filter>
并不是说它没有正确启动,而是该应用程序甚至没有出现在可以打开相关类型文件 (epub) 的可能应用程序列表中。我敢打赌,它与 mime 类型有关,并且这不起作用的文件管理器对 mime 类型有一些神奇的作用。但我特别说我不关心 mimetypes ("/") 以避免任何问题,而且我似乎无法找到有效的 mime 类型(我什至不知道是什么)它可能不是八位字节流:epub 本质上是一个 zip 文件,如果我尝试 mimetype application/zip 它会破坏所有文件管理器)。
在 Android Marshmallow 和 Nougat 中进行了测试,我不知道在 Kitkat 中是否会发生同样的情况(据我所知,旧版 Android 甚至没有内置文件管理器)。
我已尝试完全删除 mime 类型(不起作用),还尝试将所有数据条目压缩为一个,这与将它们分开一样。由于我不想强迫用户使用“已批准”的文件管理器,我需要解决这个问题,但不知道出了什么问题。
以下是意图的 logcat 消息:
I/ActivityManager: START u0 {act=android.intent.action.VIEW dat=content://com.android.externalstorage.documents/document/primary:Download/test.epub typ=application/epub+zip flg=0x3 cmp=android/com.android.internal.app.ResolverActivity} from uid 10042 on display 0
来自 Android 文件管理器(请注意,我的阅读器并未显示为可能启动的应用之一)并且:
/ActivityManager: START u0 {act=android.intent.action.VIEW dat=file:///storage/emulated/0/Download/test.epub typ=application/epub+zip flg=0x10000000 cmp=org.fictitious.epubreader/.activities.IntentResolverActivity} from uid 10114 on display 0
当我从 ES 文件管理器打开它时(并且我的应用程序正确启动)
【问题讨论】:
标签: android file android-intent