1

I'm trying to filter files using a FilePicker in Xamarin.Forms. Specifically, SQLite's .db3 files. In order to filter files in Android, you're supposed to provide the FilePicker MIME types of the files you want to show. This is what I did, based on the MIME types I found SQLite files have:

var fileTypes = new string[] { "application/x-sqlite3", "application/vnd.sqlite3" };
var file = await CrossFilePicker.Current.PickFile(fileTypes);

I have also tried putting "application/db3", "application/db" inside the fileTypes array, but to no avail. The only time I could filter in SQLite files, and some other ones out, was when I put "application/*" in the array, which means the MIME type is of an application.

These MIME types did not work for me. I have also tried getting MIME types using Xamarin's Android.Webkit.MimeTypeMap class like so:

var MIME =  MimeTypeMap.Singleton;
string sqliteMIME = MIME.GetMimeTypeFromExtension("sqlite");

I have tried passing "sqltie3", "sqltie", "db3", "db", "db0" to the function call, and the function returned null every time.


FilePicker's Github repo: https://github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows

Information I found on SQLite's MIME type:

E. Epstein
  • 739
  • 2
  • 11
  • 26
  • See if `application/pdf` returns `pdf` (or vice versa) and `text/x-java` returns `java`. If those return from `GetMimeTypeFromExtension`, etc.. correctly, but something common like does not `png` does not return `image/png` (`png` is not included in the base ASOP mime provider), then it sounds like the device is using stock ASOP and NOT providing a mime type supplier via `SetDefaultSupplier` and if so, I like to know you what device are you using – SushiHangover Sep 27 '20 at 00:49
  • I have tried using an emulated Pixel 3a [Android 9.0 - API28], a physical Pixel 3a [Android 11.0 - API30] , and a physical Xiaomi Mi A1 [Android 9.0 - API28]. Except the Xiaomi, everything worked perfectly with `pdf`, `java`, `png` and `csv` file types. The Xiaomi could not filter in the `java` files though. – E. Epstein Sep 27 '20 at 10:02
  • 1
    @E.Epstein I have check the source code of the MIME type. There is no db mime type. You could refer to the link below. https://android.googlesource.com/platform/libcore/+/android-cts-6.0_r26/luni/src/main/java/libcore/net/MimeUtils.java – Wendy Zang - MSFT Sep 28 '20 at 03:25
  • @WendyZang-MSFT, I see. So is there no way to filter in SQLite files? – E. Epstein Sep 28 '20 at 21:29
  • You could filter with the `FileName`. Try to filder with `result.FileName.EndsWith("db", StringComparison.OrdinalIgnoreCase)`. Please check the link. https://learn.microsoft.com/en-us/xamarin/essentials/file-picker?tabs=android – Wendy Zang - MSFT Sep 30 '20 at 08:20
  • @WendyZang-MSFT, I was looking for something to filter the files during the dialog, and not after, but as far as I understand it is impossible for SQLite files. Thank you for all the trouble! – E. Epstein Sep 30 '20 at 19:53
  • @E.Epstein I have posted this comment in answer. If this helps you, you could accept as answer. Thanks. – Wendy Zang - MSFT Oct 02 '20 at 08:16

2 Answers2

2

Try "application/octet-stream". It works for me.

B Conrad
  • 21
  • 2
1

You could check the source code of the MIME type. There is no db mime type. You could refer to the link below.

https://android.googlesource.com/platform/libcore/+/android-cts-6.0_r26/luni/src/main/java/libcore/net/MimeUtils.java

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17