FilePicker 不接受 sqlite 数据库文件

问题描述 投票:0回答:1

程序员! 我为 Android 编写了一个程序,它与 Sqlite3 数据库一起使用。我想通过 FilePicker 选择数据库文件。数据库具有标准的 .db 扩展。但是filePicker不接受这个文件

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"
};

此选项代码合金接受图片,但不接受我的数据库文件。我哪里错了?

android sqlite xamarin mime-types
1个回答
0
投票

如果你检查MIME类型的源代码,你可能会发现android不支持db mime类型。并使用“/”将接受所有文件。

一种解决方法是使用

application/octet-stream
而不是“application/vnd.sqlite3”。虽然是壁橱哑剧类型,可能还有一些其他文件,但要好得多。更多信息,请参阅如何在android中使用intent仅选择sqlite db文件。

另一种方法是我们自己检查文件类型,您可以在这里检查文档:选择文件

    var result = await FilePicker.PickAsync();
    if (result != null)
    {
        Text = $"File Name: {result.FileName}";
        if (result.FileName.EndsWith("db", StringComparison.OrdinalIgnoreCase)
        {
             //add your code here
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.