xamarin FilePicker不接受sqlite数据库文件

z9ju0rcb  于 5个月前  发布在  SQLite
关注(0)|答案(1)|浏览(64)

程序员!我写了一个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"
};

字符串
这个选项代码接受图片,但不接受我的数据库文件。我错在哪里?

h22fl7wq

h22fl7wq1#

如果你检查MIME类型的source code,你可能会发现android不支持db mime类型。使用“/”将接受所有文件。
一个解决方法是使用application/octet-stream而不是application/vnd.sqlite3。虽然它是壁橱mime类型,但可能还有其他一些文件,但要好得多。更多信息,请参阅How to pick only sqlite db file using intent in android.
另一种方法是我们自己检查文件类型,你可以在这里检查文档: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
        }
    }

字符串

相关问题