xamarin.forms - 如何在 Xamarin.Forms 的每个平台中访问公共(public)下载文件夹

标签 xamarin.forms xamarin.uwp

我需要创建一个备份服务,所以我打算在每个平台上保存 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/

相关文章:

c# - Xamarin.Forms 问题中的流畅设计

c# - Android 语音识别将数据传回 Xamarin Forms

c# - 通过 Xamarin 在 UWP 上使用文本转语音

c# - CurrentApp.LicenseInformation 只允许我访问一次

.net - 如何在 .NET MAUI 中为多个按钮创建单击事件

xamarin - 应用包或bundle中签名的根证书必须是可信的

uwp - 要为 UWP 开发安装哪个版本的 Windows SDK?

xamarin.forms - Xamarin 形式 : How to copy an entry value?

android - Xamarin 表格 : Push notification is not working on Android 7. 1.2

xamarin.forms - 系统无效操作异常: Page must not already have a parent