1

我有我的应用程序的生产和测试版本。两者之间的唯一区别是包名,因此两者可以同时安装在同一设备上。

这两个应用程序都有一个意图过滤器,将它们与以下文件类型相关联 android:mimeType="application/octet-stream" android:pathPattern=".*\.myfile"

步骤 1. 我安装生产版本,并在 dropBox 中打开一个文件。结果正常:我的生产版本出现在选择器菜单中。

步骤 2. 我安装测试版,并在 dropBox 中打开一个文件。RESULT FAIL:只有生产版本出现在选择器菜单中。

步骤 3. 我卸载了生产版本,并在 dropBox 中打开了一个文件。结果正常:只有测试版本出现在选择器菜单中。

在第 2 步之后,我也用其他一些应用程序进行了测试,但比较结果可能不相关,因为内容方案和 mimeTypes 不同。

Gmail OK(内容方案是"content:",mimeType 是"application/octet-stream"

Google Drive OK(内容方案是"file:",mimeType 是"application/vnd.my.custom.type"

Evernote FAIL(内容方案是"content:",mimeType 是"application/octet-stream"

Evernote 失败是因为它创建的 Intent 既没有提供正确的 mimeType,也没有提供正确的文件扩展名!

以下是我正在使用的所有意图过滤器

        </intent-filter>
        <!--
            Intent-filter for restoring via apps that use the file scheme, 
            and preserve the file-name, but not the MIME type, e.g. Dropbox.
        -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="*"
                android:mimeType="application/octet-stream"
                android:pathPattern=".*\\.wsctry"
                android:scheme="file" />
        </intent-filter>

        <!--
             Intent-filter for restoring via apps that use the content scheme, preserve
             the MIME type, but not the file name.
        -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="*"
                android:mimeType="application/vnd.winesecretary.com.backup"
                android:scheme="content" />
            <!-- Some apps (e.g. some versions of Gmail) use the file suffix as the mimeType! -->
            <data
                android:host="*"
                android:mimeType="application/wsctry"
                android:scheme="content" />
        </intent-filter>
        <!--
            Intent-filter for restoring via Google Drive and
            other apps that use the file scheme and preserve the 
            MIME type.
        -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="*"
                android:mimeType="application/vnd.winesecretary.com.backup"
                android:scheme="file" />
        </intent-filter>

        <!-- Special cases for some versions of Gmail -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <!--
            Gmail uses some strange mimeTypes when opening WS backup attachments,
            and none of them correspond to the original mimeType given by WS itself!
            -->
            <data
                android:host="gmail-ls"
                android:mimeType="application/octet-stream"
                android:scheme="content" />
        </intent-filter>
4

1 回答 1

1

在我简化了意图过滤器后,问题就消失了。

这就是我现在使用的

<!-- Intent-filter for Intents that contain the file suffix. -->
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />

    <!--  For a path to be meaningful, both a scheme and an authority must be specified. -->
    <data
        android:mimeType="*/*"
        android:host="*"
        android:scheme="file"
        android:pathPattern=".*\\.wsctry" />
</intent-filter>

<!-- Intent-filter for Intents that contain a MIME type -->
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />

    <!-- This is the original mimeType which was used when creating the file. -->
    <data android:mimeType="application/vnd.winesecretary.com.backup" />

    <!-- Some apps (e.g. some versions of Gmail) use the file suffix as the mimeType! -->
    <data android:mimeType="application/wsctry" />

    <!-- Gmail sometimes uses some strange mimeTypes when opening attachments -->
    <data
        android:host="gmail-ls"
        android:mimeType="application/octet-stream" />
</intent-filter>
于 2013-04-29T11:24:46.997 回答