我目前正在开发一个 Android 应用程序,该应用程序读取具有自定义扩展名的文件。 其中一项强制性功能是,当用户收到带有附件 .ourextension 的邮件时,应用程序必须由 gmail 推荐。
我做了一些研究,发现 Android 上的 gmail 客户端不依赖扩展名,因为在启动 Intent 的数据中,建议的文件没有扩展名。它只依赖于邮件客户端给定的 mime 类型。
问题是我们的自定义文件在邮件客户端之间的检测方式不同。例如,如果我通过 gmail 网页向自己发送我们的自定义文件,则 mime 类型被检测为 application/octet-stream。如果我的一个 friend 用 apple 邮件桌面软件发送,它会被检测为文本/xml(这很好)。在另一个邮件客户端 Evolution 上,mime 类型是 text/plain...
我们的应用程序无法处理所有这些类型!否则,将为每种类型的附件建议...
有解决办法吗?
最佳答案
使用 gmail < 4.2、gmail 4.2、Google Drive 和文件浏览器测试的使用自定义扩展名打开文件的解决方案
发送文件的代码:
sendIntent.setType("application/calc1");
Intent 过滤器:
<!-- Filter to open file with gmail version < 4.2 -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/calc1" />
<data android:pathPattern=".*\\.calc1" />
<data android:host="*" />
</intent-filter>
<!-- Filter to open with file browser or google drive -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.calc1" />
<data android:host="*" />
</intent-filter>
<!-- Filter to open file with gmail version 4.2 -->
<!-- Save file first with "save" button otherwise gmail crashes -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\.calc1" />
<data android:host="*" />
</intent-filter>
关于android - Gmail 附件和自定义扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6304082/