我需要创建一个备份服务,所以我打算在每个平台上保存 SQLite 数据库文件。卸载应用程序后,保存的文件应该可用。
我打算用下载文件夹(应该在每个平台上都可用)。
我已经创建了一个界面,并在每个平台上使用以下代码:
接口(interface) :
public interface IBackupService
{
string GetDownloadPath();
}
安卓 :
public string GetDownloadPath()
{
return Android.OS.Environment.DirectoryDownloads;
}
UWP :
public string GetDownloadPath()
{
return Windows.Storage.KnownFolders.???????;
}
我该怎么办?有可以使用的公共(public)图书馆吗?
最佳答案
根据 KnownFolders 上的文档,似乎没有通用下载文件夹。 .因此,您对 Downloads 文件夹位于每个平台上的假设似乎并不正确。
如果我们再深入一点,我们就会到达 DocumentsLibrary对于这种目的,这似乎是显而易见的选择,但事实并非如此。微软说:
The Documents library is not intended for general use. For more info, see App capability declarations. Also, see the following blog post. Dealing with Documents: How (not) to use the documentsLibrary capability in Windows Store apps
之后的段落似乎描述了我们当时必须做的事情;
If your app has to create and update files that only your app uses, consider using the app's local folder. Get the app's local folder from the Windows.Storage.ApplicationData.Current.LocalFolder property.
因此,正如我可以从您的问题中提取的那样,您只想为您的应用程序使用存储空间,因此
Windows.Storage.ApplicationData.Current.LocalFolder
根据微软的说法似乎是正确的选择。
关于xamarin.forms - 如何在 Xamarin.Forms 的每个平台中访问公共(public)下载文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39511743/