在Windows Phone 8.1中尝试从后台audiotask更新livetile: "提供的应用程序标识

本文关键字:quot livetile 标识 应用程序 更新 audiotask Phone Windows 后台 | 更新日期: 2023-09-27 18:12:07

我有一个音乐播放器,想用播放曲目的专辑更新livetile。因此,每次轨道改变时,我调用单独的Windows运行时组件中的一个方法。方法如下所示:

public async void CreateLivetile(string albumart, string artist, string trackname)
{
    try
    {
        // constants
        string textElementName = "text";
        string imageElementName = "image";
        // Create a tile update manager
        var updater = TileUpdateManager.CreateTileUpdaterForApplication();
        updater.EnableNotificationQueue(true);
        updater.Clear();
        // wide 310x150
        var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150PeekImage03);
        tileXml.GetElementsByTagName(textElementName).LastOrDefault().InnerText = string.Format(artist + " - " + trackname);
        var image = tileXml.GetElementsByTagName(imageElementName).FirstOrDefault();
        if (image != null)
        {
            var src = tileXml.CreateAttribute("src");
            src.Value = albumart;
            image.Attributes.SetNamedItem(src);
        }
        // square 150x150
        var squaredTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);
        squaredTileXml.GetElementsByTagName(textElementName).FirstOrDefault().InnerText = string.Format(artist + " - " + trackname);
        image = squaredTileXml.GetElementsByTagName(imageElementName).LastOrDefault();
        if (image != null)
        {
            var src = squaredTileXml.CreateAttribute("src");
            src.Value = albumart;
            image.Attributes.SetNamedItem(src);
        }
        updater.Update(new TileNotification(tileXml));
        updater.Update(new TileNotification(squaredTileXml));
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
        // Inform the system that the task is finished.
        //_deferral.Complete();
    }
}

当方法到达这一行时:

var updater = TileUpdateManager.CreateTileUpdaterForApplication();

我得到这个错误:

The application identifier provided is invalid.

在Windows Phone 8.1中尝试从后台audiotask更新livetile: "提供的应用程序标识

这个方法在应用程序(前端)中工作得很好…

有解决办法:http://social.msdn.microsoft.com/forums/windowsapps/en - us/83498107 fe0d - 4 - a8b f3 - 93 - 02 - d484983953/tileupdatemanager抛出exception?forum=wpdevelop

直接提供ID即可:TileUpdateManager.CreateTileUpdaterForApplication("软件")

您发现了模拟器中的一个常见错误。

摘自微软的一个博客:

我们发现了导致这个失败的两种情况。第一个是期间在Visual模拟器中运行应用程序时进行应用程序开发工作室。更新磁贴时可能会抛出此错误。的建议在本地机器设置下运行应用程序[…].

其次,此故障可能发生在底层通知平台在用户的机器上不可用。如果通知平台遇到了一个问题,导致它终止,它导致磁贴通知和更新失败。呼唤TileUpdateManager.CreateTileUpdaterForApplication正常检索获取包的全名,创建通知端点,然后执行通知子系统的包和应用程序名验证。最后两个步骤中的任何一个出现问题都可能导致"应用程序失败"所提供的标识符无效",生成此例外。

参见:

  • 更新win8 Metro应用程序中的磁贴
  • 为什么二级瓷砖的标识符无效?
  • "cant-update-secondary-tile"