2

I am trying to figure out the best way to determine a file extension given a mime type in android.

This is typically coming in the form of a content uri so I get the mime type as follows:

ContentResolver contentResolver = context.getContentResolver();
String mimeType = contentResolver.getType(uri);

From there I have been using MimeTypeMap:

MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String extension = mimeTypeMap.getExtensionFromMimeType(mimeType);

This works great in most cases however there are a few glaring holes, one of them being that there is no entry for "audio/mp4".

Is there a more complete mapping I can use that is built into Android? Or any other ideas?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
  • Do you get `audio/mp4` when calling `String mimeType = contentResolver.getType(uri);`? – KRK Aug 29 '19 at 05:55

1 Answers1

1

Is there a more complete mapping I can use that is built into Android?

No, sorry.

Or any other ideas?

Bake a MIME type map of your own into your app. See:

...and so on.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491