1

在我的应用程序第一次启动期间,我想让用户能够授予对某些同步应用程序(如 Dropbox)的访问权限。

我的 UWP 应用程序有什么方法可以检测到 Dropbox 是否已安装?然后我可以提示用户通过 FolderPicker 提供对该文件夹的访问权限......

4

1 回答 1

1

无法通过 UWP 应用确定是否安装了 Dropbox。或者,至少,可能不是从 UWP 应用访问 Dropbox 的推荐方法。

在 Windows 上,用户的 Dropbox 文件夹位置存储在%localappdata%\Dropbox\info.jsonWPF/WinForms/Console 应用程序中,您可以使用以下内容:-

using Newtonsoft.Json.Linq;
using System;
using System.IO;

public static class Dropbox
{
    private static string _Path;
    public static string Path
    {
        get { return _Path ?? (_Path = GetPath()); }
    }

    static string GetPath()
    {
        var appDataPath = Environment.GetFolderPath(
                                       Environment.SpecialFolder.LocalApplicationData);
        var filePath = System.IO.Path.Combine(appDataPath, @"Dropbox\info.json");

        dynamic dropboxInfo = JObject.Parse(File.ReadAllText(filePath));

        string folderPath = dropboxInfo.personal.path;

        return folderPath;
    }
}

由于无法访问%localappdata%此方法,这是 UWP 应用程序中的第一个障碍。

这样一来,您要么在不知道是否已安装的情况下提示用户输入 Dropbox 文件夹位置,要么使用 Dropbox SDK 连接到 Dropbox 并独立于用户通过 Dropbox 客户端在本地拥有的任何副本访问文件。

于 2018-11-21T10:29:53.043 回答