Xaml 如何在Windows Phone 8.1应用程序清单中添加文件类型关联?

Xaml 如何在Windows Phone 8.1应用程序清单中添加文件类型关联?,xaml,windows-phone-8.1,Xaml,Windows Phone 8.1,我正在尝试使用以下代码访问KnownFolders.MusicLibrary中的文件 internal async void Update() { StorageFolder rootFolder = KnownFolders.MusicLibrary; ScanFolder(rootFolder); } private async void ScanFolder(StorageFolder storageFolder)

我正在尝试使用以下代码访问
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 ... >
            }
        }
    }
无法通过GUI添加
文件类型关联
(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>

音乐录音机
本杰明
资产\StoreLogo.png
6.3.1
6.3.1
mp3
.mp3
AgHostSvcs.dll

奇怪的事情(它只涉及WP8.1 Silverlight),但正如我所检查的,可以通过xaml编辑器添加文件类型关联:右键单击package.appxmanifest文件,选择查看代码F7。在您的
中找到
部分,无需在文件关联中添加.mp3它是保留的,将被忽略。您只能访问SD卡库,而不能访问手机存储器。

请查看问题。我提到将节点添加到xml不起作用。添加了一个屏幕截图。@Benjaminidele我刚检查过。等等,我将尝试分享一个示例。我显然将节点添加到了错误的父节点。在
节点中添加
扩展
节点是正确的。现在我仍然需要解决拒绝访问的异常。@Benjaminidele添加功能音乐库、可移动存储,看看是否有帮助。请注意,在VS中调试时,如果要更改mainfest文件中的fileTypeAssociations,则必须先在设备或模拟器上卸载该应用,然后再点击“调试”,否则,更改将不会被注册。虽然这在理论上可以回答问题,但请在此处包含答案的基本部分,并提供链接以供参考。
<?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>
  </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>