积极答复者
后台任务怎么更新TILE

问题
-
我在做一个音乐播放类小软件 类似于QQ音乐那样 播放流音乐
我在后台任务里面清加了SystemMeiaTransportControl ButtonPressed事件
当按下播放下一首 后 会请求获得下一首的音乐相关信息 包括音乐的URL 艺术家 专辑名称 专辑图片URL等等信息
然后使用backgroundMediaPlayer.Current.SetUri 音乐就能播放了
我以为我接来直接写更新Tile 就可以了 但是实践证明不行
所以想问一下我该 怎么做会更好
- 已移动 Cheryl_WPS 2015年10月26日 19:19 移动
2015年10月15日 5:11
答案
-
你好,
要实现你说的这个效果,你可以在ButtonPressed事件中添加更新磁贴的代码即可以实现,但是这里有一些细节方面的东西需要你注意。
首先,在后台任务里使用到Toast,Tile等,需要你指定applicationID,例如:
TileUpdateManager.CreateTileUpdaterForApplication("App").Clear();
这里为什么我的ApplicationID是“APP”呢? 你可以在“View-Code”模式下,查看你项目的Package.appxmanifest
所以具体到你的项目中,你要改成对应的ApplicationID.
下面是我在后台任务里更新磁贴的代码,测试运行没有问题:
TileUpdateManager.CreateTileUpdaterForApplication("App").Clear(); TileUpdateManager.CreateTileUpdaterForApplication("App").EnableNotificationQueue(true); var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image); var tileImage = tileXml.GetElementsByTagName("image")[0] as XmlElement; tileImage.SetAttribute("src", "ms-appx:///Assets/1.jpg"); var tileNotification = new TileNotification(tileXml); TileUpdateManager.CreateTileUpdaterForApplication("App").Update(tileNotification); tileImage.SetAttribute("src", "ms-appx:///Assets/2.jpg"); tileNotification = new TileNotification(tileXml); tileNotification.Tag = "myTag"; TileUpdateManager.CreateTileUpdaterForApplication("App").Update(tileNotification);
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 Xavier Xie-MSFT 2015年11月1日 7:47
- 已建议为答案 Xavier Xie-MSFT 2015年11月1日 7:48
- 已标记为答案 Fred Bao 2015年11月10日 1:56
2015年11月1日 7:47
全部回复
-
你好,
要实现你说的这个效果,你可以在ButtonPressed事件中添加更新磁贴的代码即可以实现,但是这里有一些细节方面的东西需要你注意。
首先,在后台任务里使用到Toast,Tile等,需要你指定applicationID,例如:
TileUpdateManager.CreateTileUpdaterForApplication("App").Clear();
这里为什么我的ApplicationID是“APP”呢? 你可以在“View-Code”模式下,查看你项目的Package.appxmanifest
所以具体到你的项目中,你要改成对应的ApplicationID.
下面是我在后台任务里更新磁贴的代码,测试运行没有问题:
TileUpdateManager.CreateTileUpdaterForApplication("App").Clear(); TileUpdateManager.CreateTileUpdaterForApplication("App").EnableNotificationQueue(true); var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image); var tileImage = tileXml.GetElementsByTagName("image")[0] as XmlElement; tileImage.SetAttribute("src", "ms-appx:///Assets/1.jpg"); var tileNotification = new TileNotification(tileXml); TileUpdateManager.CreateTileUpdaterForApplication("App").Update(tileNotification); tileImage.SetAttribute("src", "ms-appx:///Assets/2.jpg"); tileNotification = new TileNotification(tileXml); tileNotification.Tag = "myTag"; TileUpdateManager.CreateTileUpdaterForApplication("App").Update(tileNotification);
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 Xavier Xie-MSFT 2015年11月1日 7:47
- 已建议为答案 Xavier Xie-MSFT 2015年11月1日 7:48
- 已标记为答案 Fred Bao 2015年11月10日 1:56
2015年11月1日 7:47