0

@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.

Sorry IwontTell
  • 466
  • 10
  • 29

1 Answers1

1

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.

Blu
  • 821
  • 4
  • 17
  • 1
    Please try with empty **abc.ext**, Your code works for pdf but not for ext: See `string[] allowedTypes = { "application/ext" };` and `string[] allowedTypes = { "application/pdf" };` **PIC1**:https://i.ibb.co/yXJGvfz/ext.png **PIC2;** https://i.ibb.co/Q66wDVR/pdf.png – Sorry IwontTell Aug 18 '20 at 14:56
  • MIME type of **PDF is application/pdf** . Whereas My **encrypted file has MIME type of application/octet-stream** . But many other files also have same type So I can't use this phenomena. I used this https://htmlstrip.com/mime-file-type-checker – Sorry IwontTell Aug 18 '20 at 15:05
  • ticking it to make you motivated as issue solved but also review my edit that is correct answer. Goodies – Sorry IwontTell Aug 28 '20 at 18:19
  • "application/foo" works for me. The .foo files are enabled and all of the others are grayed out. – Charles May 27 '22 at 22:18