Bug 11853 - MimeTypeMap.Singleton.GetExtensionFromMimeType returns null
Summary: MimeTypeMap.Singleton.GetExtensionFromMimeType returns null
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.4.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-18 15:53 UTC by Alex Anikin
Modified: 2013-04-24 18:00 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Alex Anikin 2013-04-18 15:53:59 UTC
Hey -

I need get MimeType for extension using this method. (Show intent to open file.)
It works good 1-2 times - I can see a correct list of available apps, but after that it begins return null.
At the same time MimeTypeMap.Singleton.HasExtension return true.

Device is Motorolla Xoom, but another app work fine and show a correct list of available apps.
Comment 1 Alex Anikin 2013-04-18 16:01:23 UTC
And one addition - if i get not null mimetype I see intent with available apps - 2 apps, but another application propose another list - 4 apps.

Code:
var file = new Java.IO.File(TemporaryFilePath);
var targetUri = Android.Net.Uri.FromFile(file);
var extension = MimeTypeMap.GetFileExtensionFromUrl (targetUri.ToString());
var mimeType =  MimeTypeMap.Singleton.GetExtensionFromMimeType(extension);

Intent openIn = new Intent (Intent.ActionView);
openIn.SetDataAndType (targetUri, mimeType);
_view.Activity.StartActivity (openIn);
Comment 2 Alex Anikin 2013-04-23 11:00:20 UTC
Hi! Any luck?
Comment 3 Jonathan Pryor 2013-04-24 13:07:48 UTC
I believe that this is an API usage issue, not a binding issue. As such I'm not sure where to start.

Please provide a complete, self-contained, reproducible test case that demonstrates the problem. (Even better would be the corresponding Java app which is "the same" but exhibits different behavior.)

> var file = new Java.IO.File(TemporaryFilePath);
> var targetUri = Android.Net.Uri.FromFile(file);
> var extension = MimeTypeMap.GetFileExtensionFromUrl (targetUri.ToString());
> var mimeType =  MimeTypeMap.Singleton.GetExtensionFromMimeType(extension);

This code doesn't make sense. `extension` will be a file extension, e.g. ".p3", yet you're passing it to MimeTypeMap.GetExtensionFromMimeType(), which will want a mime-type, not an extension.

For example, MimeTypeMap.Singleton.GetExtensionFromMimeType("mp3") returns null, as "mp3" isn't a mime-type.

MimeTypeMap.Singleton.GetExtensionFromMimeType("video/mpeg"), meanwhile, returns "mpga".
Comment 4 Alex Anikin 2013-04-24 18:00:22 UTC
My mess. Closed.