0

I want to get the File extension from a Chooser Intent on an Samsung Galaxy S5.

The first returns an empty string and for the second one i get an empty string aswell.

The uri I get from the Chooser intent is

content://com.android.providers.downloads.documents/document/12537

string test = MimeTypeMap.GetFileExtensionFromUrl(uri.ToString()); // empty
string fName = uri.LastPathSegment.Split(new char[] { '\\', ':', '/' }).Last(); // Empty aswell
joachim
  • 652
  • 2
  • 7
  • 23

2 Answers2

1

Try this:

    Uri yourUrl; //your uri
    ContentResolver contentResolver = getContext().getContentResolver();
    String mimeType = contentResolver.getType(yourUrl);
    MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
Mr.O
  • 813
  • 7
  • 14
0

Note: This answer addresses part of the problem. For a complete solution (in the form of a library), look at Paul Burke'answer. Get real path from URI, Android KitKat new storage access framework

Sudhi
  • 403
  • 4
  • 8