【问题标题】:Android: File Extension Intent Filter does not work properly with GMail/Downloads appAndroid:文件扩展名意图过滤器无法与 GMail/Downloads 应用程序一起正常工作
【发布时间】:2018-01-13 03:10:57
【问题描述】:

我有一个应用程序允许用户备份数据并希望他们能够通过文件管理器、GMail 和下载系统应用程序单击备份文件。

我在清单文件中定义了以下意图...

        <intent-filter
            android:label="Simple Backup File"
            android:priority="999" >

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

            <data
                android:scheme="http"
                android:host="*"
                android:pathPattern=".*\\.sbu" />

            <data
                android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.sbu" />

            <data
                android:scheme="ftp"
                android:host="*"
                android:pathPattern=".*\\.sbu" />

            <data
                android:scheme="ftps"
                android:host="*"
                android:pathPattern=".*\\.sbu" />

            <data
                android:scheme="content"
                android:host="*"
                android:pathPattern=".*\\.sbu" />

            <data
                android:scheme="file"
                android:host="*"
                android:pathPattern=".*\\.sbu" />
        </intent-filter>

如果我从文件管理器中单击 .sbu 文件,而不是从 GMail 或下载列表中单击,则上述方法有效。我确实读到我需要一个 mimeType 才能使内容方案正常工作,但是当我将 mimeType 定义为 */*application/octet-stream 时,该功能甚至在文件管理器中停止工作。

我做错了什么?第一次写入文件时需要设置任何设置吗?你会如何最好地处理我的情况。

【问题讨论】:

    标签: android android-intent backup mime-types file-extension


    【解决方案1】:

    我通过将内容与文件数据方案一起放入其自己的意图过滤器组来使其工作,两者都具有应用程序/八位字节流的 mime 类型。

            <intent-filter android:priority="999" >
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.OPENABLE" />
    
                <data
                    android:scheme="http"
                    android:host="*"
                    android:pathPattern=".*\\.sbu" />
    
                <data
                    android:scheme="https"
                    android:host="*"
                    android:pathPattern=".*\\.sbu" />
    
                <data
                    android:scheme="ftp"
                    android:host="*"
                    android:pathPattern=".*\\.sbu" />
    
                <data
                    android:scheme="ftps"
                    android:host="*"
                    android:pathPattern=".*\\.sbu" />
    
                <data
                    android:scheme="file"
                    android:host="*"
                    android:pathPattern=".*\\.sbu" />
            </intent-filter>
    
            <intent-filter android:priority="999" >
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.OPENABLE" />
    
                <data
                    android:scheme="file"
                    android:mimeType="application/octet-stream"
                    android:pathPattern=".*\\.sbu" />
    
                <data
                    android:scheme="content"
                    android:mimeType="application/octet-stream"
                    android:pathPattern=".*\\.sbu" />
            </intent-filter>
    

    【讨论】:

    • 这会打开所有文件的 Gmail 附件。不只是 sbu,还有 abc、xyz 等。我不知道如何让它过滤 Gmail 文件扩展名?
    猜你喜欢
    • 2013-03-04
    • 2011-04-15
    • 2023-03-11
    • 2010-12-16
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多