Search code examples
c#androidxamarinfilepicker

Pick file with specific file extension xamarin.android


@vividos @jfversluis

Expected Behavior

I want to open files with specific file extension filter.

Actual Behavior

Lets suppose I have file named "abc.ext", So I want to filter all files with that specific extension i.e .ext.
Currently I seen android is supporting only MIME types not extension. Is that so ?
This not working. I am using FilePicker-Plugin-for-Xamarin-and-Windows.

var fileTypes = new string[] { "ext/*" }; 
FileData fileData = await CrossFilePicker.Current.PickFile(fileTypes);

This what developer said:

Unfortunately Android lets you only specify MIME types to filter the selectable files (the others are grayed out and unselectable). If you know the MIME type, that's good, but in other cases you should check the FileName property and its file extension if it's an acceptable one.

I want that other files with filters other than ".ext" should be garyed out.
So is there any workaround for that problem that android accept only accept MIME type ?
Or any other method ? My files are basically binary and encrypted files, So it may not have a well and unique MIME type.
Any alternative approach would be appreciated.


Solution

  • As i said,

    string[] allowedTypes = { "application/pdf" };

    FileData fileData = await CrossFilePicker.Current.PickFile(allowedTypes);

    is working fine for me & as you said everything was grayed out, thats cuz your extension file isnt present in your device folder.

    enter image description here

    You can refer the image above, everything will be grayed out except the format extension you mention in allowedTypes i.e pdf

    If you need some more help, you can ask.