android - 如何在 Android 中注册我的应用程序以打开具有自定义文件类型的电子邮件附件?

标签 android intentfilter

我的应用程序应该处理我的自定义 .rmc 文件。我的用户将通过电子邮件接收它们,我希望我的应用程序能够打开它们,但最好尽可能少地打开我的应用程序无法处理的其他文件类型。

我在 Android 中使用了以下 intent-filter 不幸的是,它无法在 gmail 中打开附件(gmail 给出了一条错误消息,指出没有应用程序可以打开 rmc 文件)。

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


            <category android:name="android.intent.category.LAUNCHER"/>

            <category android:name="android.intent.category.DEFAULT"/>
            <data android:scheme="content" android:mimeType="*/*" android:host="*" android:pathPattern=".*\\.rmc"/>
            <data android:mimeType="application/octet" />
            <data android:mimeType="application/octet-stream" />
        </intent-filter>

为了比较,下面的过滤器捕获了文件,但捕获的太多了:

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


            <category android:name="android.intent.category.LAUNCHER"/>

            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/*" />
        </intent-filter>

最佳答案

My app is supposed to handle my custom .rmc files.

Android 中对文件扩展名的支持非常少。

I use the following intent-filter in Android with unfortunately doesn't work for opening attachemnts in gmail

Gmail 或任何其他应用不需要使用 content Uri使用文件扩展名的值。所以,欢迎您拥有 <intent-filter> ,但不要假设它适用于所有电子邮件客户端或任何其他任意应用程序。

How do I register my app in Android to open email attachments with a custom filetype?

你不知道。

如果发送电子邮件的电子邮件客户端将为您的内容提供特定的独特 MIME 类型,请为 android:mimeType 使用该 MIME 类型.例如,如果您要从某个服务器发送电子邮件,您应该能够控制附件的添加方式以及附件使用的 MIME 类型。

否则,为该数据找到一些使用独特 MIME 类型的分发机制(例如,从 Web 服务器下载,您将服务器配置为使用该 MIME 类型为您的文件提供服务)。然后,将该 MIME 类型用于 android:mimeType .

关于android - 如何在 Android 中注册我的应用程序以打开具有自定义文件类型的电子邮件附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55815525/

相关文章:

android - 如何从root重新启动adb到用户模式?

android - 保持 wifi radio 打开的不同可能性?

java - 本地广播接收器异常 : android. app.IntentReceiverLeaked?

android - RECEIVE_BOOT_COMPLETED 和 "Exported receiver does not require permission"

Android 监听 ACTION_DOCK_EVENT

android - 1个月限制申请免费使用

android - MenuItemCompat.setOnActionExpandListener 已弃用

Android BroadCastReceiver 滞后应用程序

java - android 从 fragment 调用 MainActivity 函数

android - 仅在子 Activity 中使用 Monkey(android 调试)