Notifications on Secondary Tiles in windows phone 7
Notifications on Secondary Tiles in windows phone 7:
in this blog am going explain you about update the secondary tile from the notification service
Since 256-MB Windows Phone Devices fully support Push Notifications, it is possible to change the Secondary Tile content with a little extra effort. In this episode of EvenTiles we will take a look at adding Tile Notifications to the application. Those Tile Notifications are delivered to individual Windows Phone devices through the Microsoft Push Notification Service, just like all other Push Notifications.
In this blog entry we will concentrate on the client side, mainly providing code that registers the application. To test the application, we will make use of a little ASP.NET application that is based on the sample that is introduced in the How to Send and Receive Tile Notifications for Windows Phone article. It is beyond the scope of this blog entry to show how to host a web service (for instance by making use of Azure functionality).
NOTE: The ASP.NET test application cannot be created using Visual Studio 2010 Express for Windows Phone. You either need at least Visual Studio 2010 Professional or the free Visual Web Developer 2010 Expressto create the test application.
Push Notifications on Secondary Tiles
Something that is not entirely clear in the referred How to article, or in the documentation around Push Notifications on MSDN is the fact that sending Tile Updates through Push Notifications is not limited to the Application Tile, but you can also use the same approach to update Secondary Tiles. Since we are dealing with a Secondary Tile in the EvenTiles application, we will focus on updating a Secondary Tile. In the ASP.NET test application we will create the following message to update our tile:
Updating a Seondary Tile
- // Create the Tile message.
- string tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
- "<wp:Notification xmlns:wp=\"WPNotification\">" +
- "<wp:Tile ID=\"/MainPage.xaml?TileId=Secondary\">" +
- "<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
- "<wp:Count>" + nrRuns.ToString() + "</wp:Count>" +
- "</wp:Tile> " +
- "</wp:Notification>";
Creating a Secondary Tile
- private void btnInstall_Click(object sender, RoutedEventArgs e)
- {
- StandardTileData NewTileData = new StandardTileData
- {
- BackgroundImage = new Uri("Background.png", UriKind.Relative),
- Title = "EvenTiles",
- Count = 0,
- BackBackgroundImage = new Uri("BackBackTile.png", UriKind.Relative),
- BackTitle = "EvenTiles",
- BackContent = App.ActualSecBackContent
- };
- ShellTile.Create(new Uri("/MainPage.xaml?TileId=Secondary", UriKind.Relative), NewTileData);
- }
Getting a Notification Channel
- public class TileNotifications
- {
- public const string tileNotificationChannel = "EvenTilesChannel";
- public void SetupChannel()
- {
- var pushChannel = HttpNotificationChannel.Find(tileNotificationChannel);
- if (pushChannel == null)
- {
- pushChannel = new HttpNotificationChannel(tileNotificationChannel);
- pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
- pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
- pushChannel.Open();
- pushChannel.BindToShellTile();
- }
- else
- {
- pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
- pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
- // Display the URI for testing purposes. Normally, the URI would be passed back to a web service.
- System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
- }
- }
If you are no longer interested in receiving Tile Notifications for your application, you can close a previously opened HttpNotificationChannel, make sure to dispose of it and also make sure to unsubscribe to events to prevent against leaking memory. The following code snippet shows how you can stop receiving Tile Notifications:
Closing a Notification Channel
- public void CloseChannel()
- {
- var pushChannel = HttpNotificationChannel.Find(tileNotificationChannel);
- if (pushChannel != null)
- {
- pushChannel.ChannelUriUpdated -= PushChannel_ChannelUriUpdated;
- pushChannel.ErrorOccurred -= PushChannel_ErrorOccurred;
- pushChannel.Close();
- pushChannel.Dispose();
- App.GetLiveTileNotifications = false;
- }
- }
Handling Push Channel Events
- void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
- {
- switch (e.ErrorType)
- {
- case ChannelErrorType.ChannelOpenFailed:
- App.GetLiveTileNotifications = false;
- break;
- case ChannelErrorType.PayloadFormatError:
- SetupChannel();
- break;
- default:
- CloseChannel();
- break;
- }
- }
- void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
- {
- System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
- App.GetLiveTileNotifications = true;
- }
The ASP.NET test application does so in aThreadPool thread. You can specify the number of updates and the time between updates. Each time another update is send, the count property that will be displayed on the front side of the Secondary Tile that EvenTiles pinned on the start screen will be updated.
Even though Background Agents are not supported on 256-MB devices, we have a nice workaround by making use of Push Notifications because they are fully supported. Of course this means that you need to invest more in server side programming, but it also means that the end user experience of a Windows Phone application can be very similar on both a 512-MB device and a 256-MB device. For this to work, the target device must have a network connection.
The complete sample code for EvenTiles so far can be downloaded here. If you want to test the application on a 256-MB device (emulator), you will need to download and install the Windows Phone 7.1.1 SDK Update as well. The ASP.NET test application is also available as a separate download. In order to run this test application, you need a version of Visual Studio 2010 that supports creating and debugging ASP.NET applications.
The following video shows how to subscribe to Tile Notifications from within the EvenTiles application and how to test the newly added functionality by means of an APS.NET test application.
Using Push Notifications to update Live Tiles on Windows Phone
Labels:
WindowsPhone
Thanks for provide the information.
For more information please visit here windows phone push notifications .
Thanks for provide the information.
For more information please visit here windows phone push notifications .