Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

EvenTiles from Start to Finish - Part 16

DZone's Guide to

EvenTiles from Start to Finish - Part 16

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

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

<App xmlns=""
     ProductID="{883385e6-52e5-4835-83db-8a17499b5767}"
     Title="EvenTiles"
     RuntimeType="Silverlight"
     Version="1.0.0.0"
     Genre="apps.normal"
     Author="Maarten Struys"
     Description="Sample description"
     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

private string GetVersionNumber()
{
    string[] version = XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("Version").Value.Split('.');
 
    StringBuilder sb = new StringBuilder(version[0]);
    sb.Append(".");
    sb.Append(version[1]);
    versionNumber = sb.ToString();
 
    return versionNumber;
}
 
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    tbVersion.Text = GetVersionNumber();
}


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 EmailCompose Task

private void btnEmail_Click(object sender, RoutedEventArgs e)
{
    StringBuilder sb = new StringBuilder("Feedback / Support for EvenTiles ");
    sb.Append(versionNumber);
 
    var emailComposeTask = new EmailComposeTask
    {
        To = "mstruys@hotmail.com",
        Subject = sb.ToString()
    };
    emailComposeTask.Show();
}

 

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

private void btnReview_Click(object sender, RoutedEventArgs e)
{
    MarketplaceReviewTask reviewTask = new MarketplaceReviewTask();
    reviewTask.Show();
}

 

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

private void btnMore_Click(object sender, RoutedEventArgs e)
{
    var searchTask = new MarketplaceSearchTask
    {
        ContentType = MarketplaceContentType.Applications,
        SearchTerms = "DotNETForDevices"
    };
    searchTask.Show();
}


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.



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).

 




Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Published at DZone with permission of Maarten Struys, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}