0

I write a program for Android, which works with Sqlite3 database. I want to pick database file by FilePicker. Database has standard .db extension. But the FilePicker does not accept this file.

var options = new PickOptions
{
    FileTypes = new FilePickerFileType
    (new Dictionary<DevicePlatform, IEnumerable<string>>
    {
        { DevicePlatform.Android, new[] { "application/vnd.sqlite3", "image/jpeg" } },
        { DevicePlatform.UWP, new[] { ".db" } }
    }),
    PickerTitle = "Please, select database file"
};

This options code alloys to accept pictures, but doesn't accept my database file. Where I'm wrong?

5
  • Use only "*/*".
    – blackapps
    Commented Dec 24, 2023 at 9:31
  • It works, but accepts all the files
    – user21587900
    Commented Dec 24, 2023 at 10:17
  • Yes. I hope you understand why.
    – blackapps
    Commented Dec 24, 2023 at 10:46
  • I understand and I guess it's fine with me, but for interest, how to accept database files only?
    – user21587900
    Commented Dec 24, 2023 at 11:51
  • I have no idea. But now that this works you have time to search in peace for it ;-)
    – blackapps
    Commented Dec 24, 2023 at 11:52

1 Answer 1

0

If you check the source code of the MIME type, you may find no db mime type supported by android. And use "*/*" will accept all files.

One workaround is to use application/octet-stream instead of application/vnd.sqlite3. Though it is the closet mime type, there may be some other files, but much better. More info, please refer to How to pick only sqlite db file using intent in android.

Another way is that we check the file type ourselves, you could check the document here : Pick file

    var result = await FilePicker.PickAsync();
    if (result != null)
    {
        Text = $"File Name: {result.FileName}";
        if (result.FileName.EndsWith("db", StringComparison.OrdinalIgnoreCase)
        {
             //add your code here
        }
    }