Search code examples
sqlitexamarinfiltermime-typesfilepicker

How to filter SQLite3 files using FilePicker in Xamarin.Forms


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:


Solution

  • 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