从邮件附件打开 x509 证书 (.crt) 时接收 Intent

Receiving Intent while opening an x509 certificate (.crt) from a mail attachment

当用户在 Android 上 client/application 的 client/application 邮件中单击此附件时,我想 read/extract 来自 .crt 文件附件的数据。我在 AndroidManifest.xml 中使用了以下意图过滤器:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="content" />
            <data android:mimeType="application/x-x509-user-cert"
                android:pathPattern=".*\.crt"/>
        </intent-filter>

但他不是 work.Also,从邮件应用程序 android 打开 CRT 文件时提示安装证书。这是否意味着指定的操作应该是别的东西?这个 intent 过滤器有什么问题?

Android 测试版本:4.1.2

您可能会发现 this source code 有用。作者为每个证书文件扩展名设置了两行,其中一行被注释掉以示区别。

此外,根据电子邮件应用程序发布附件意图的方式,方案可能是 "file" 而不是 "content"。我对此有点不清楚。我建议两者都试一下。 :-)

<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" />
    <!-- <data android:mimeType="*/*" />-->
    <data android:pathPattern=".*\.crt" />
    <data android:host="*" />
</intent-filter>
<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" />
    <data android:mimeType="*/*" />
    <data android:pathPattern=".*\.crt" />
    <data android:host="*" />
</intent-filter>

源代码来自:https://github.com/netmackan/CertTools/blob/master/AndroidManifest.xml

对我来说效果很好的 Intent 过滤器:

        <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:mimeType="application/x-x509-ca-cert" />
        </intent-filter>

尽管当我尝试使用以下代码片段查找 MIME 类型时:

    String mimetype;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        mimetype = mime.getMimeTypeFromExtension(extension);
    }
    Log.d(TAG,mimetype);

输出:application/x-x509-user-cert
意图过滤器中使用的 mime 类型不同。但是,它有效。如果有人对此发表评论,那将很有用。