Android: Action_Send return Extra_Stream: 如何获取文件的扩展名

Android: Action_Send return Extra_Stream: How to get the extension of the file

有没有办法提取内容的扩展名:从 Action_Send 返回的 uri。

当收到 Action_Send 时,我可以打开流到 Extra_Stream 给出的内容,但我需要使用适当的文件扩展名来命名文件。

I need to name the file with proper extension of the file

这不是文件。是一段内容。

比如这个网页的"proper extension"是什么?它的 URL 是

A Uri 的工作方式相同。它是某些内容的不透明句柄。不要假设它有文件扩展名。

可以通过DocumentFile获取MIME类型。从那里,MimeTypeMap 可能会建议您可以使用的文件扩展名。