Android 应用程序已分配给任何可能的文件 - 应仅分配给我的自定义文件

标签 android android-manifest mime-types email-attachments intentfilter

我正在尝试将我的 Android 应用分配给扩展名为“kka”的自定义文件(json 内容)。 在以下情况下,我希望能够打开我的应用程序并读取 *.kka 文件: 1. *.kka 作为邮件附件(gmail 客户端) 2. *.kka 作为文件存储在文件系统中,例如下载/文件夹

我的 AndroidManifest.xml 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mydomain.kka" >
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.mydomain.kka.MainActivity"
            android:label="@string/app_name" >
            <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.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" android:pathPattern=".*\\.kka" android:mimeType="*/*"/>
                <data android:scheme="content" android:pathPattern=".*\\.kka" android:mimeType="application/stream-octet"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

这是我发现能够启动我的应用程序的唯一配置,将 *.kka 作为 gmail 客户端中的附件和文件系统中的文件。

问题是我的应用程序出现在我想打开电子邮件附件或文件系统上的文件的所有可能位置,无论它是什么类型的文件,所以我的 KKATest 应用程序在分配的应用程序列表中,例如XML、PDF,甚至 APK 等。 它似乎忽略了我在 AndroidManifest 文件中明确提到的文件扩展名。

这种情况发生在搭载 Android 4.4 的 Galaxy Nexus、搭载 Android 4.3 的 Galaxy S4 以及其他一些机型上。

我在 StackOverflow 上阅读了很多建议,但没有人解决我的问题。我的 list 文件有什么问题?

最佳答案

我遇到了同样的问题。我需要从 SD 卡和电子邮件附件中打开我的文件。对我来说,这也是试错,但这是我的解决方案:

<intent-filter> <!-- Intent filter for opening files from system -->
            <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" />
            <data android:host="*" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.locx" />
        </intent-filter>
        <intent-filter> <!-- Intent filter for open files from email -->
            <data android:scheme="content" />

            <action android:name="android.intent.action.VIEW" />

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

            <data android:mimeType="application/octet-stream" />
            <data android:pathPattern=".*\\.locx" />
        </intent-filter>

locx 显然是我的文件类型。 顺便说一句:我只测试了 Gmail 应用程序,从其他论坛帖子我了解到其他电子邮件应用程序可能会有所不同。

关于Android 应用程序已分配给任何可能的文件 - 应仅分配给我的自定义文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21146566/

相关文章:

android - hive 上的 db4o Db4oException : File format incompatible

html - 由于 MIME 类型而未加载样式表

mime-types - 二维码 MIME 类型

android - 有效地转换Web UI以在iPhone或Android设备上更好地查看?

android - 致命异常 : java. lang.SecurityException:缺少插入徽章的权限

android - 在 Broadcastreceiver 中检测 USB - 我错过了什么?

java - 以流的形式发送 Pdf 附件中的电子邮件

Android fragment 对话框在使用 weightSum 时似乎忽略了 layoutMargin 或 layoutWidth

c# - Android Java 到 Mono C# - MapView.LayoutParams

android - 尽管 ellipsize=end,但带有长文本的 Textview 会在 GridLayout 中推出其他 View