Category Archives: Marketplace

EvenTiles and TrialMode

In part 17 of EvenTiles we will take a look at Trial Mode. When an application supports trial mode, users can first try the application before buying it. It is up to you as the application developer to determine which functionality is available in the application when running in trial mode. Even though trial mode makes your application slightly more complex, the advantage of implementing trial mode is that you will only have to submit one single version of your application that customers can either try or buy. The application is started with either a trial license or a full license (when the user purchased the application). Inside the application, you can make use of an API to determine if a user is running your application in trial mode or not. From a technical point of view, there are no restrictions to trial mode, so you can even provide full application functionality in trial mode. Of course that does not make sense, because you typically want to use trial mode to invite end users to try your application after which they hopefully get so excited about your application that they determine to buy it.

NOTE: Be careful with providing a limited time to execute a fully functional application in trial mode, because end users can simply reinstall your application to again run the application for a certain amount of time in trial mode.

Let’s assume that EvenTile has two different modes of operation, implemented through Trial Mode. In Trial Mode, EvenTiles is fully functional without restrictions, however, the application will display ads on the main page (adding the actual advertisements to EvenTiles will be covered later in this series). As soon as users purchase EvenTiles, advertisements will be disabled. In trial mode, the application also contains functionality to retrieve location information in order to receive localized advertisements, although the user can disable location retrieval through the Settings Page of the application. However, if a user purchases the application, location information will not be retrieved and it does not make sense to have a toggle switch in the Settings Page to enable / disable location retrieval. Finally, if the user runs EvenTiles in trial mode, they have the option to purchase the application from within the application’s About Page. Of course, this option is only available in trial mode, if the application is already purchases, the About Page allows a user to display more applications that were published by DotNETForDevices.

Let’s begin by finding out how we can determine if the application is currently running in Trial Mode. In order to do so, as long as the user is running the application in Trial Mode, we will check the current application’s license each time the application starts or becomes the foreground application, and set a Boolean property accordingly. We also store the current value of that Boolean property in our application settings. When a user has purchased the application, we only have to check the application settings which results in faster starting / resuming of the application. The following code snippet shows how to determine if we are running in Trial mode:

Running in Trial Mode?
  1. public const string keyTrialMode = "K_TRIAL";
  2. public static bool IsTrialMode { get; private set; }
  3.  
  4. private void Application_Launching(object sender, LaunchingEventArgs e)
  5. {
  6.     if (!appSettings.Contains(keyTrialMode))
  7.     {
  8.         appSettings[keyTrialMode] = true;
  9.     }
  10.  
  11.     IsTrialMode = (bool)appSettings[keyTrialMode];
  12.  
  13.     if (IsTrialMode)
  14.     {
  15.         CheckTrialMode();
  16.     }
  17. }
  18.  
  19. private void CheckTrialMode()
  20. {
  21.     IsTrialMode = new LicenseInformation().IsTrial();
  22. }

This snippet only shows checking for Trial Mode when the application is launched. We first determine if we already stored the current license type in our application settings. If we assume we are running in Trial Mode we need to check if the license type has chanced since the last time the user ran the application. Since correct license information will only be added when the application is downloaded from the Windows Phone Marketplace, it might be a little tricky to test this functionality. When you installed the application locally on an unlocked device during testing of your application, or when you execute the application from within Visual Studio, the LicenseInformation.IsTrial method always returns false. With a little bit of conditional compilation, we can easily change this for test purposes. In the following code snippet you can see that we can test Trial mode when we are running the application in Debug mode and when the TRIAL symbol is defined. By simply setting this symbol to NO_TRIAL we can test the application for both different license types.

Testing Trial Mode
  1. #if DEBUG
  2. #define TRIAL
  3. #endif
  4.  
  5. using System.Windows;
  6. using Microsoft.Phone.Marketplace;
  7.  
  8. namespace EvenTiles
  9. {
  10.     public partial class App : Application
  11.     {
  12.         private void CheckTrialMode()
  13.         {
  14. #if ! TRIAL
  15.             IsTrialMode = new LicenseInformation().IsTrial();
  16. #endif
  17.         }

In the OnLaunching method of the application, the IsTrialMode property is initialized to true and optionally modified by executing the CheckTrialMode method. If you want to test the application as if it was purchased by a user, you can simply change TRIAL to NO_TRIAL, recompile and execute the application again.

NOTE: If you take this approach, make sure that you install a clean copy of the application to a device or the emulator when switching back to trial mode. The way the code is organized, once the IsTrialMode property is set to false, the call to the LicenseInformation.IsTrial method is never executed again. To install a clean copy, make sure to rebuild your application in Visual Studio before deploying it, instead of simply building the application. After a rebuild, not only the application is replaced on the target device, but the entire IsolatedStorage area of the application is cleaned.

Testing a purchased app
  1. #if DEBUG
  2. #define NO_TRIAL
  3. #endif
  4.  
  5. using System.Windows;
  6. using Microsoft.Phone.Marketplace;
  7.  
  8. namespace EvenTiles
  9. {
  10.     public partial class App : Application
  11.     {
  12.         private void CheckTrialMode()
  13.         {
  14. #if ! TRIAL
  15.             IsTrialMode = new LicenseInformation().IsTrial();
  16. #endif
  17.         }

Since Debug is not set in release mode, you will always call the LicenseInformation.IsTrial method when the application is deployed to a device.

Since we now have determined if the application is running in Trial Mode or not, we can simply use this information to display / hide the location retrieval toggle button on the Settings Page. Also, when can alter the functionality of one of the buttons on the About Page. If the application runs in Trial Mode, the user can purchase the application from within the About Page. If the user already has purchased the application, they can use the same button to check more applications from the same publisher, as shown in the following code snippet:

Changing button behavior
  1. public partial class AboutPage : PhoneApplicationPage
  2. {
  3.     public AboutPage()
  4.     {
  5.         InitializeComponent();
  6.  
  7.         btnMore.Content = App.IsTrialMode ? "Purchase EvenTiles now" : "More from DotNETForDevices";
  8.     }
  9.  
  10.     private void btnMore_Click(object sender, RoutedEventArgs e)
  11.     {
  12.         if (App.IsTrialMode)
  13.         {
  14.             MarketplaceDetailTask detailTask = new MarketplaceDetailTask();
  15.             detailTask.Show();
  16.         }
  17.         else
  18.         {
  19.             var searchTask = new MarketplaceSearchTask
  20.             {
  21.                 ContentType = MarketplaceContentType.Applications,
  22.                 SearchTerms = "DotNETForDevices"
  23.             };
  24.             searchTask.Show();
  25.         }
  26.     }
  27. }

When the application is running, it either shows the location toggle switch and it provides different functionality in the About Page.

image

The following video shows how to add Trial Mode to the EvenTiles application. It also shows how you can test this functionality by making use of some conditional compilation.

Adding TrialMode to the application and testing TrialMode.

To be able to experiment with the functionality of EvenTiles as it is right now, the sample code is available for dowload here. In the next episode of EvenTiles we will talk about adding support to run EvenTiles on 256-MB Windows Phone devices.

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

Advertisements

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

Publishing my first Windows Phone 7 application

MobileAppTileSmallOver the last year I have spent a lot of time talking about Windows Phone 7 development, both at (international) conferences, for students and at companies. During these presentations I always used a significant part of my speaking time to show Visual Studio 2010 in action. Live coding is something I like to do, and definitely helps showing an audience how powerful the development tools for Windows Phone 7 application development are. One question I got frequently was to show the applications I already had published on the Windows Phone 7 Marketplace. Up until now I have not really been interested in publishing Windows Phone 7 applications, teaching folks how to develop these applications is just more fun for me. However, over the last couple of weeks I decided to create a simple application for publication on Marketplace. Even though simple, the application is making use of MVVM instead of making use of code behind files. Making use of MVVM helped testing the application and definitely increases maintainability. To my surprise, getting the application certified and published was a very simple process. It was just a matter of submitting my (obfuscated) XAP file, some artwork, screen shots and a description. A few more details needed to be filled out on the submission pages, like a category under which the application will be visible on Marketplace, the price for the application and support for Trial mode. All in all, submitting the application took less then 15 minutes. After some waiting time (which can vary between a couple of hours and a few working days), I got an email, indicating successful submission to Marketplace. This process is easy and fast. Funny enough, it also made me feel good to see my own application available on Marketplace. I really start getting excited about submitting Windows Phone 7 applications. Just wait and see. I am pretty sure I will get more applications out to Marketplace. Oh, just in case you are curious: You can find my first ever published Windows Phone 7 application by clicking on this link to Marketplace. Note: This link will work from a Windows Phone 7, or from a PC with Zune software installed.