If
you wish to let potential buyers try your application first, you must
let Microsoft know that that trial functionality is "allowed"—i.e.,
available—when you submit it to the Windows Phone Marketplace. If you
specify that trials are allowed, then, in the Marketplace, Microsoft
will automatically include a Free Trial button, as shown in Figure 1.
An important consideration for application developers is that, at
present, trials do not expire—they can be replaced by full application
versions only if customers decide to purchase applications.
The implementation
of trial functionality is entirely up to the application developer; the
developer may choose to limit the functionality of the application and
prompt the user to purchase the full version of an application to access
all application features. Alternately, the developer may choose to
prevent the trial application from running after a certain time period.
The way to accomplish these time-limited trials would be to either store
the date the application was run for the first time and stop after a
certain time period, or to store the number of times the application has
been run and disallow its execution after a certain number of runs.
Microsoft recommends
that application providers prompt users of their trial software during
the trial period to purchase a full version. If a user selects the
purchase option, control of the application should be programmatically
transferred to Windows Phone Marketplace and the application details
page should be displayed. Within the Windows.Phone.Tasks
namespace, there is a set of methods that make it quick and easy to
complete Marketplace tasks, including searching within the application
or music categories and showing the application details page. If, after reviewing
application details, the user decides to purchase your application, the
trial license is replaced with the full license, and the execution of
the IsTrial method should indicate that the application is no longer running in the trial mode.
We will now explore in detail both the IsTrial method and the Windows Phone Marketplace API classes that are used to do this work.
1. Using the IsTrial Method
Using the IsTrial method is straightforward: this method is part of the Microsoft.Phone.Marketplace.LicenseInformation
class, and it returns true if an application is being used on a trial
basis (i.e., when the user clicks the Free Trial button in the Windows
Phone Marketplace instead of Buy) and false
if an application is running with a full license. Windows Phone
Marketplace handles installation of trial and full licenses and
determines when each is appropriate. However, when you execute the IsTrial
method while you're developing an application, or before the
application user has acquired a trial or a full application license, its
behavior is unpredictable. Microsoft documentation currently says that IsTrial
would return true, while our tests show the opposite. Regardless of the
outcome during the development stage, we should assume that the IsTrial
method will work as designed while an application is in development and
make provisions for the application to execute properly when it is
running under either a trial license or a full license.
The short walkthrough that follows demonstrates the use of the IsTrial
method and prints a message onto the screen regardless of whether the
current application is running under a trial or a full license.
First, let's create a new application and name it "TrialSample."
Launch Visual Studio 2010 Express for Windows Phone and create a new Windows Phone Application project. Name it "TrialSample."
Now add some user interface elements.
From the Toolbox, drag and drop a textblock onto the application design surface. Since you are only getting familiar with the IsTrial method, leave the name of the textblock unchanged (textBlock1) and adjust its width to occupy the entire width of the screen.
Next, let's code the demo.
Open MainPage.xaml.cs (right-click MainPage.xaml and select View Code), and add the following statement to the top of the page:
using Microsoft.Phone.Marketplace;
In the MainPage() constructor, add the following code right after InitializeComponent().
LicenseInformation lic = new LicenseInformation();
if (lic.IsTrial())
{
textBlock1.Text = "You are running a trial version of our software!";
}
else
{
textBlock1.Text = "Thank you for using the full version of our software!";
}
Press F5 to run the application to see the results of the IsTrial
method execution. When the application comes up, you should see a
message stating whether you are running a trial version of your
application (i.e., the IsTrial method returned true) or the full version.
In the next section, you get to
explore options that go beyond simply displaying a text message when
the user is executing the trial version of our software. Namely, Windows
Phone Marketplace exposes a set of classes to help the user review the
details and pay for the full license of our application.