Как добавить сопоставление типов файлов в манифест приложения Windows Phone 8.1?

Я пытаюсь получить доступ к файлам в KnownFolders.MusicLibraryсо следующим кодом.

    internal async void Update()
    {
        StorageFolder rootFolder = KnownFolders.MusicLibrary;
        ScanFolder(rootFolder);
    }

    private async void ScanFolder(StorageFolder storageFolder)
    {
        var items = await storageFolder.GetItemsAsync();

        foreach (var item in items)
        {
            if (item is StorageFolder)
            {
                ScanFolder(item as StorageFolder);
            }
            else if (item is StorageFile)
            {
                var fs = new FileStream(item.Path, FileMode.Open, FileAccess.Read);
                < ... snip ... >
            }
        }
    }

у меня есть MusicLibrary Возможность проверена, чтобы я мог использовать KnownFolders.MusicLibrary, Похоже, это не дает мне доступа к файлам библиотеки, потому что я получаю следующую ошибку:

+       [System.UnauthorizedAccessException]    

{System.UnauthorizedAccessException: Access to the path 'C:\Data\Users\Public\Music\tmp' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   at MusicTrackerPhone.Library.<ScanFolder>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)}    System.UnauthorizedAccessException

Невозможно добавить FileType Association через графический интерфейс (и узел не разрешен в xml).

Как добавить необходимые объявления для моего приложения?

Полный Package.appxmanifest:

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
  <Identity Name="aad31163-0d67-49ba-b569-80ff4d773fa0" Publisher="CN=Benjamin" Version="1.0.0.0" />
  <mp:PhoneIdentity PhoneProductId="2e54a5f6-5319-4dd2-9bad-1fe5290a0eeb" PhonePublisherId="1b03f58e-5a39-414f-9324-2cab834debfd" />
  <Properties>
    <DisplayName>MusicTrackerPhone</DisplayName>
    <PublisherDisplayName>Benjamin</PublisherDisplayName>
    <Logo>Assets\StoreLogo.png</Logo>
  </Properties>
  <Prerequisites>
    <OSMinVersion>6.3.1</OSMinVersion>
    <OSMaxVersionTested>6.3.1</OSMaxVersionTested>
  </Prerequisites>
  <Resources>
    <Resource Language="x-generate" />
  </Resources>
  <Applications>
    <Application Id="x2e54a5f6y5319y4dd2y9bady1fe5290a0eebx" Executable="AGHost.exe" EntryPoint="MainPage.xaml">
      <m3:VisualElements DisplayName="MusicTrackerPhone" Square150x150Logo="Assets\SquareTile150x150.png" Square44x44Logo="Assets\Logo.png" Description="MusicTrackerPhone" ForegroundText="light" BackgroundColor="#464646">
        <m3:DefaultTile Square71x71Logo="Assets\SquareTile71x71.png">
        </m3:DefaultTile>
        <m3:SplashScreen Image="Assets\Splashscreen.png" />
      </m3:VisualElements>
      <Extensions>
        <Extension Category="windows.fileTypeAssociation">
          <FileTypeAssociation Name=".mp3">
            <DisplayName>mp3</DisplayName>
            <SupportedFileTypes>
              <FileType ContentType="audio/mp3">.mp3</FileType>
            </SupportedFileTypes>
          </FileTypeAssociation>
        </Extension>
      </Extensions>
    </Application>
  </Applications>
  <Capabilities>
    <Capability Name="musicLibrary" />
    <Capability Name="removableStorage" />
  </Capabilities>
  <Extensions>
    <Extension Category="windows.activatableClass.inProcessServer">
      <InProcessServer>
        <Path>AgHostSvcs.dll</Path>
        <ActivatableClass ActivatableClassId="AgHost.BackgroundTask" ThreadingModel="both" />
      </InProcessServer>
    </Extension>
  </Extensions>
</Package>

2 ответа

Решение

Странная вещь (это касается только WP8.1 Silverlight), но, как я уже проверял, можно добавить ассоциации FileType через редактор xaml: щелкните правой кнопкой мыши файл package.appxmanifest, выберите View code F7. Найти раздел <Extensions> в вашем <Application (вероятно, сразу после </m3:VisualElements>) и добавьте первую ассоциацию FileType вручную:

  </m3:VisualElements>
  <Extensions>
    <Extension Category="windows.fileTypeAssociation">
      <FileTypeAssociation Name=".mp3">
        <DisplayName>mp3</DisplayName>
        <SupportedFileTypes>
          <FileType ContentType="audio/mp3">.mp3</FileType>
        </SupportedFileTypes>
      </FileTypeAssociation>
    </Extension>
    // other extensions
  </Extensions>

После того, как вы добавите первую, следующую ассоциацию FileType, которую вы сможете добавить через графический интерфейс, теперь она будет доступна в поддерживаемых декларациях.

НЕТ. Необходимо добавить.mp3 в файловую ассоциацию, она зарезервирована и будет игнорироваться. Вы можете получить доступ только к библиотеке SD-карт, не хранящейся в памяти телефона.

Другие вопросы по тегам