Can't get Android Firefox to open files with a

2019-06-09 13:15发布

I want my app to handle files called *.mcmidi from browser, email or storage.

I have found that the following intent-filter data element works for android native browser and for android chrome:

<data android:scheme="content" android:mimeType="*/*" android:pathPattern=".*\\.mcmidi" />

and this works for android firefox:

<data android:scheme="file" android:pathPattern=".*\\.mcmidi" />

but if I try to use both then firefox stops being able to open the downloaded files. It seems like firefox doesn't work if any intent-filter specifies a mimeType.

(I've been testing so many combinations of these intent-filters trying to find one that works everywhere)

Does anyone know why firefox is doing this, or any way to work around it?

1条回答
相关推荐>>
2楼-- · 2019-06-09 13:29

Ok I worked it out. Chrome and Android browsers use the scheme="content" entry. Firefox uses the scheme="file" entry. If you use the mimeType="*/*" entry then all new email alerts will open the app chooser with my app, which is also no good. Opening file attachments from gmail use scheme="content" but with a different mimeType. File explorer apps generally use scheme="file" with the path extension.

Because they all need different intent-filters, I have used activity-alias to alias my activity three different ways for the different apps, so that they all pass the file content to my app and don't interfere with each other or add themselves as generic file handlers (which is always very irritating). So I have this:

<activity
    android:name="my.Activity"
    android:label="@string/label1"
    android:exported="true" >
    <!-- the main intent filter allows chrome and native browsers to open .mcmidi files with my app -->     
    <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:scheme="content" android:mimeType="application/x-mcmidi"  android:pathPattern=".*\\.mcmidi" />
    </intent-filter>
</activity>

<!-- This alias will cause file explorer apps to open *.mcmidi files with my app -->
<activity-alias
    android:name="my.ActivityFileAlias"
    android:targetActivity="my.Activity"
    android:label="@string/label1"
    android:exported="true" >

    <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:scheme="file" android:pathPattern=".*\\.mcmidi" />
    </intent-filter>
</activity-alias>

<!-- This alias will cause gmail and the native mail apps to open *.mcmidi files with my app -->
<activity-alias
    android:name="my.ActivityEmailAlias"
    android:targetActivity="my.Activity"
    android:label="@string/label1"
    android:exported="true" >

    <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:scheme="content" android:mimeType="application/octet-stream" android:pathPattern=".*\\.mcmidi" />
    </intent-filter>
</activity-alias>

Which I worked out with a few clues and loads of trial and error. Hope it helps someone.

查看更多
登录 后发表回答