0

我正在 DragonBoard 410c 上使用 Windows 10 IoT 开发客户特定应用程序。在此应用程序中,必须知道哪个驱动器是 SD 卡,哪个驱动器是附加 USB 记忆棒。我曾经通过驱动器号使用

KnownFolders.RemovableDevices

因为SD卡应该有驱动器号“D”。但是,在一块板上,SD 卡突然出现驱动器号“E”,我的代码失败了。

因此我开始使用

var deviceInfos = await DeviceInformation.FindAllAsync( DeviceClass.PortableStorageDevice );

枚举可移动驱动器,然后在Id每个对象的字符串中搜索DeviceInformation特定模式:

private StorageFolder _sdCard;
private StorageFolder _usbDrive;

foreach( DeviceInformation info in deviceInfos )
{
    string id = info.Id.ToUpper();

    try
    {

        if( id.Contains( SDId ) )
        {                            
            _sdCard = StorageDevice.FromId( info.Id );
        }
        else if( id.Contains( USBId ) )
        {
            _usbDrive = StorageDevice.FromId( info.Id );
        }

    }
    catch( Exception e)
    {
        Debug.WriteLine( "########## Error " + e );
    }

}

不幸的是,StorageDevice.FromId()抛出NotImplementedException.

我在.appxmanifest. 访问任何可移动存储设备上的文件都没有任何问题。有没有人遇到过类似的问题并找到解决方案?StorageFolder如果可能连接了额外的 USB 记忆棒,是否有人对可靠地检索 SD 卡有不同的想法?

4

1 回答 1

0

刚刚完成问题后,我自己找到了解决方案,尽管我对此不太满意。使用

StorageFolder                removableDevices = KnownFolders.RemovableDevices;
IReadOnlyList<StorageFolder> drives           = await removableDevices.GetFoldersAsync();

驱动器中的第一个元素始终代表 SD 卡,这也在此处说明:https://docs.microsoft.com/de-de/windows/uwp/files/access-the-sd-card

但我认为这不是一个非常可靠的解决方案,我仍在寻找其他方法。

于 2017-08-14T11:12:31.973 回答