static string GetExtension(Context context, Android.Net.Uri uri) { string extension; //Check uri format to avoid null if (uri.Scheme.Equals(ContentResolver.SchemeContent)) { //If scheme is a content MimeTypeMap mime = MimeTypeMap.Singleton; extension = mime.GetExtensionFromMimeType(context.ContentResolver.GetType(uri)); } else { //If scheme is a File //This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file name with spaces and special characters. extension = MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(new Java.IO.File(uri.Path)).ToString()); } return(extension); }
public bool CheckType(ContentResolver resolver, Uri uri) { MimeTypeMap map = MimeTypeMap.Singleton; if (uri == null) { return(false); } string type = map.GetExtensionFromMimeType(resolver.GetType(uri)); foreach (string extension in mExtensions) { if (extension.Equals(type)) { return(true); } string path = PhotoMetadataUtils.GetPath(resolver, uri); if (path != null && path.ToLower().EndsWith(extension)) { return(true); } } return(false); }