EvenTiles from Start to Finish–Part 16

In the previous episode of this series about how to develop a Windows Phone application from scratch you learned how to create the UI of a more or less typical About Page using Expression Blend. The About Page contains nothing fancy, just a number of TextBlocks and a few Buttons. Right now we are ready to add some functionality to the About Page to

  • Display the application’s version in a TextBlock
  • Submit an email containing remarks and/or suggestions to the application’s publisher
  • Submit a review for the application
  • Check Marketplace for more applications, available from the same publisher

screen1

In itself, these are all small, relatively easy and partly unrelated actions. However, the latter 3 items, even though different, all have something in common. In order to achieve the desired result, we will make use of functionality that is available in a Windows Phone, but outside of our application. To use that specific functionality, we will make use of different Windows Phone Launchers. You can think of a Launcher as a separate application that can be shared by our applications to allow users to perform some common tasks in a uniform and consistent way. The fact that a Launcher starts a separate, built-in application, has some consequences for our application that makes use of the Launcher. When the application we launched becomes active, our application will be moved to the background. This means that our application will temporarily be paused and even be tombstoned in low memory / resource situations. Since we already took care of properly dealing with our application being moved to the background (see episode 7 about Tombstoning), this is not a big deal but it is good to realize what is happening under the covers of the Windows Phone platform.

Note: Usually Launchers are mentioned together with Choosers because they provide similar functionality and operate more or less the same. The big difference between them is that a Chooser (as the word implies) is capable of selecting some data (for instance a picture) and return the selected item to our application. Choosers will be covered in a later episode of EvenTiles.

As always, it makes a lot of sense to see things in action and to take a look at actual code. That is the reason why, besides these series of blog entries, there are also accompanying videos and sample code available for download.

Retrieving the application’s version number

The first goal we want to achieve is to retrieve the version number of our application and display it in the About page. Since our application stores its own version number in its manifest file, we want to retrieve it from there.

NOTE: The version number must also be specified when submitting an application to the Windows Phone Marketplace. According to the documentation, this version number must match your application’s version number but maintaining it in your manifest file is a separate activity. There is yet another version number, stored in the application’s AssemblyInfo.cs file and modifiable through the project properties. In EvenTiles we ignore the latter and retrieve the version number immediately from the application’s manifest file.

Application version numbers consist of major, minor, build, and revision components. To match the version number as it is showed in the Windows Phone Marketplace, we only want to display the major and minor parts of the application. Since the application manifest file is just another XML file, we can easily retrieve the version number from it.

Version info in manifest file
  1. <App xmlns=""
  2.      ProductID="{883385e6-52e5-4835-83db-8a17499b5767}"
  3.      Title="EvenTiles"
  4.      RuntimeType="Silverlight"
  5.      Version="1.0.0.0"
  6.      Genre="apps.normal"
  7.      Author="Maarten Struys"
  8.      Description="Sample description"
  9.      Publisher="DotNETForDevices">

To retrieve the version number and to display it in a Textblock inside the About Page, we can just load the XML from the manifest file and find the value of the version attribute of the App element. The reason why this works is because the application manifest file (WMAppManifest.xml) is deployed to the phone as part of the XAP file.

Get version from manifest file
  1. private string GetVersionNumber()
  2. {
  3.     string[] version = XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("Version").Value.Split('.');
  4.  
  5.     StringBuilder sb = new StringBuilder(version[0]);
  6.     sb.Append(".");
  7.     sb.Append(version[1]);
  8.     versionNumber = sb.ToString();
  9.  
  10.     return versionNumber;
  11. }
  12.  
  13. private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
  14. {
  15.     tbVersion.Text = GetVersionNumber();
  16. }

Sending an email

A nice feature inside a Windows Phone application is the possibility for end users to get in touch with you through email. Making this as easy as possible for end users might result in you getting some useful feedback about your application and might also increase the user’s satisfaction with your application, which in turn might lead to better and more reviews. To send an email programmatically to a fixed email address is very simple. You simply can make use of the EmailComposeTask and even pre-populate information in the email to make it easier for the end user to send out an email. The following code shows how to send an email programmatically:

Using the EmailComposeTask
  1. private void btnEmail_Click(object sender, RoutedEventArgs e)
  2. {
  3.     StringBuilder sb = new StringBuilder("Feedback / Support for EvenTiles ");
  4.     sb.Append(versionNumber);
  5.  
  6.     var emailComposeTask = new EmailComposeTask
  7.     {
  8.         To = "mstruys@hotmail.com",
  9.         Subject = sb.ToString()
  10.     };
  11.     emailComposeTask.Show();
  12. }

NOTE: In order to test this functionality, you have to use a physical device. The Windows Phone Emulator will throw an exception when using the email compose task.

Submitting a review

If you know how to use one Windows Phone Launcher you basically know how to use them all. Since we already saw that sending an email is a very simple operation (creating a new object, setting some properties and calling the Show method on the object), submitting a review should not be difficult. The following code shows how to allow your users to submit a review by using the MarketplaceReviewTask Launcher:

Submitting a review
  1. private void btnReview_Click(object sender, RoutedEventArgs e)
  2. {
  3.     MarketplaceReviewTask reviewTask = new MarketplaceReviewTask();
  4.     reviewTask.Show();
  5. }

screen2

Of course, this code can be extended, for instance by storing in the application settings if a review has already been submitted. If so, we can for instance remove the button to submit a review from the application. We can also verify if we currently have a data connection in order to submit a review. All this functionality is omitted in this sample code.

Checking for more applications

Using the same approach as described before, we can also allow the user to look for more applications that we already published on the Windows Phone Marketplace. This can be achieved by using the MarketplaceSearchTask, again in a similar way:

Finding apps on Marketplace
  1. private void btnMore_Click(object sender, RoutedEventArgs e)
  2. {
  3.     var searchTask = new MarketplaceSearchTask
  4.     {
  5.         ContentType = MarketplaceContentType.Applications,
  6.         SearchTerms = "DotNETForDevices"
  7.     };
  8.     searchTask.Show();
  9. }

The MarketplaceSearchTask is a very nice marketing instrument because you can guide users of your application to other Windows Phone applications you have published.

The following video shows how to create the functionality we described in this episode of EvenTiles. It also shows two of the described Launchers in action, one running in the emulator, one on a physical device.

Using Launchers inside a Windows Phone Application

To be able to experiment with this working implementation of EvenTiles, especially to understand how the application interacts with the PeriodicTask through a file in IsolatedStorage, the sample code is available for dowload here. In the next episode of EvenTiles we will talk about implementing Trial Mode in your application to allow users to try the application before optionally buying it.

EvenTilesIf you want to see EvenTiles already in action on your Windows Phone, you can also install the latest free version from Marketplace. Remember that this application is not meant to be extremely useful, although it contains similar functionality that “serious” applications have. Just go ahead and get your free copy of EvenTiles from Marketplace at this location: http://www.windowsphone.com/en-US/search?q=EvenTiles (or search on your phone for EvenTiles in the Marketplace application).

2 thoughts on “EvenTiles from Start to Finish–Part 16

  1. Another way of getting the version info (alongside other relevant info) is to get it from the assembly itself:

    public class AssemblyInformation
    {
    readonly Assembly _assembly;

    public AssemblyInformation()
    : this(Assembly.GetExecutingAssembly())
    { }

    public AssemblyInformation(Assembly assembly)
    {
    _assembly = assembly;
    }

    public string Version
    {
    get { return _assembly.FullName.Split(‘,’)[1].Split(‘=’)[1]; }
    }

    string GetValue(Func getValue) where T : Attribute
    {
    var a = (T)Attribute.GetCustomAttribute(_assembly, typeof(T));
    return a == null ? “” : getValue(a);
    }
    }

    The nice thing here is that you can bind to these properties, eliminating the need to manually set the Text property in code-behind.

    This can be done with all of the Assembly attributes, so getting the Name and Copyright info is equally trivial:

    public string Title
    {
    get { return GetValue(a => a.Title); }
    }

    public string Copyright
    {
    get { return GetValue(a => a.Copyright); }
    }

Comments are closed.