Android棉花糖6.0.1,如何从内容URI检查文件是否为媒体文件?

Android棉花糖6.0.1,如何从内容URI检查文件是否为媒体文件?,android,share,media,android-6.0-marshmallow,Android,Share,Media,Android 6.0 Marshmallow,当我从gallery共享图片时,在接收到意图的活动中,我得到了内容URI,但URI.getAuthority()返回“0@media". 问题是,即使对于PDF,它也会为getAuthority()返回相同的值。在我的活动中,如何区分媒体文件和其他文件(例如:PDF) 我仅在MM 6.0.1中遇到此问题,感谢您的帮助 ContentResolver cR = context.getContentResolver(); MimeTypeMap mime = MimeTypeMap.getSingl

当我从gallery共享图片时,在接收到意图的活动中,我得到了内容URI,但URI.getAuthority()返回“0@media". 问题是,即使对于PDF,它也会为getAuthority()返回相同的值。在我的活动中,如何区分媒体文件和其他文件(例如:PDF)

我仅在MM 6.0.1中遇到此问题,感谢您的帮助

ContentResolver cR = context.getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getExtensionFromMimeType(cR.getType(pass_your_URI));
因此,如果所选文件是扩展名为
jpeg
的图像,
类型
将返回
jpeg
。但是,只要调用
cR.getType(传递您的URI)
就会返回
mime/jpeg
,您也可以使用它来区分URI之外的媒体类型