我现在有两个自定义文件类型的应用程序(扩展名为.ffx和.tcb)。当从Gmail应用程序中的附件打开时,Intent既不包括文件名,也不包括最初分配的自定义MIME类型(application/freqfinder和application/timecardbuddy)。
主机=(com.谷歌.安卓.通用汽车.sapi)
方案=含量
您可以使用以下newendian@gmail.com/message_attachment_external/%23thread-f%3A1736258334946004772/%23msg-f%3A1736258334946004772/0.1
片段=空
MIME=应用程序/八位字节流
如何确保打开正确的应用程序?Android甚至不允许用户从多个应用程序中进行选择。
是否有办法拒绝应用内部的Intent,使其正确定向?或者我是否应该编写代码将显式Intent从一个应用发送到另一个应用?
编辑:一位用户联系我,询问他的设备默认使用的另一个应用程序,因为它也有MIME=application/octet-stream文件类型。Android是否真的没有机制来理解并非所有的application/octet-stream文件都进入同一个应用程序?
1条答案
按热度按时间k4emjkb11#
I now have two apps with custom filetypes (extensions .ffx and .tcb)
Custom file extensions have never been practical on Android IMHO. They have been very impractical since Android 7.0, six years ago.
When opened from an attachment within Gmail app, the Intent includes neither the filename nor the originally assigned custom mimetypes (application/freqfinder and application/timecardbuddy).
I don't know how Gmail would find out about those MIME types. They are not on the official roster , nor do they follow the rules for vendor-specific MIME types.
How can I make sure that the proper app is opened?
Your apps would need to have an
<intent-filter>
matching thatIntent
(content
scheme andapplication/octet-stream
MIME type). The app would need to attempt to read in the content and make one of two or three determinations:In case 3, you would show some sort of "sorry!" error message. If you elect to also add support for case 2, you could either:
Uri
along to it, includingFLAG_GRANT_READ_URI_PERMISSION
(and, if needed,FLAG_GRANT_WRITE_URI_PERMISSION
) in yourIntent
to start an activity in the other app (and fall back to the message if you get anActivityNotFoundException
, indicating that your other app is not installed)