I have an instrumented ebook reader app that can be opened in two different ways, one way is through another app that downloads the content directly from a server and then launches the reader. The other is by opening the ebook from the filesystem. The former works just fine. The latter works, [i]but only for specific file managers[/i]. It works with Astro and with ES file managers. It doesn't work with the default Android file manager or with AndExplorer (this is obvioulsy not an exhaustive test).
Here is the relevant bit from the manifest:
<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>
It's not that it doesn't launch correctly, it's that the app doesn't even show up in the list of possible apps to open files of the relevant type (epubs). My bet is that it has something to do with the mime type and that the file managers for which this doesn't work do something magic with mime types. But I specifically say I don't care about mimetypes ("/") to avoid any problems, and I can't seem to find a mime type that does work (I don't even know what it could be other than octet-stream: an epub is essentially a zip file, and if I try mimetype application/zip it breaks for all file managers).
Tested in Android Marshmallow and Nougat, I don't know whether the same happens in Kitkat (insofar as I know, older Android didn't even have a built-in file manager).
I have tried removing mime type altogether (doesn't work) and have also tried squashing all the data entries into a single one, which does the same as leaving them separate. As I don't want to force users to use an "approved" file manager, I need to solve this, but have no idea what is wrong.
Here are the logcat messages for the intents:
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
from the Android file manager (note that my reader doesn't show up as one of the possible apps to launch) and:
/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
when I open it from ES File Manager (and my app launches correctly)
it's that the app doesn't even show up in the list of possible apps to open files of the relevant type (epubs)
That is because you are only supporting the file scheme.
If you look at the failing Uri (content://com.android.externalstorage.documents/document/primary:Download/test.epub), you will notice that it has the content scheme, not the file scheme.
If you want to support the content scheme, change your <intent-filter> to:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="application/epub+zip"/>
</intent-filter>
Then, use ContentResolver and openInputStream() to read in the content identified by the Uri, as that works for both file and content schemes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With