简体   繁体   English

如何提取内容URI的文件类型

[英]How to extract the filetype of a content-URI

My activity receives a content URI like 我的活动收到类似的内容URI

content://data/thing/something/2342365356 内容:// data / thing / something / 2342365356

If another app shares anything with an image/* intentfilter. 如果另一个应用程序与image / * intentfilter共享任何内容。

But if an user selects one picture and one video on google photos and shares it, the intent is still image/jpg and my app crashes. 但是,如果用户在Google照片上选择了一张照片和一个视频并进行共享,则意图仍然是image / jpg,并且我的应用程序崩溃了。 I want to go thorugh the URI-array and figure out what type of File they lead to and handle it appropiately. 我想了解一下URI数组,找出它们导致的文件类型并适当地处理它。 How can I do that? 我怎样才能做到这一点?

Call getType() on a ContentResolver , passing in the Uri , to find out the MIME type associated by the content identified by that Uri . 传递给Uri ContentResolver调用getType() ,以查找由该Uri标识的内容所关联的MIME类型。

Also note that a Uri is not a file, and the content identified by the Uri does not need to be a file. 另请注意, Uri不是文件,并且Uri标识的内容也不必是文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM