Android自定义文件类型内容意图过滤器

5fjcxozz  于 2022-12-09  发布在  Android
关注(0)|答案(1)|浏览(133)

我现在有两个自定义文件类型的应用程序(扩展名为.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文件都进入同一个应用程序?

k4emjkb1

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 that Intent ( content scheme and application/octet-stream MIME type). The app would need to attempt to read in the content and make one of two or three determinations:

  1. Yes, this stream has the data in the expected format, in which case the app can go ahead and use it
  2. No, this stream does not have the data in the expected format, but it happens to match the other format
  3. No, this stream does not have the data in the expected format, and it is unrecognizable
    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:
  • Show a message in your app explaining that the user needs to use the other app (perhaps with a button to install that app), or
  • Forward the Uri along to it, including FLAG_GRANT_READ_URI_PERMISSION (and, if needed, FLAG_GRANT_WRITE_URI_PERMISSION ) in your Intent to start an activity in the other app (and fall back to the message if you get an ActivityNotFoundException , indicating that your other app is not installed)

相关问题