Windows Phone 7 Development : Understanding Trial and Full Modes (part 1) - Using the IsTrial Method

2/19/2011 5:42:24 PM
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.

Figure 1. AFree Trial button is available for the applications that support 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."

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

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

  1. 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;

  2. 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!";

    textBlock1.Text = "Thank you for using the full version of our software!";

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

  •  Mobile Application Security : SymbianOS Security - Application Packaging
  •  Mobile Application Security : SymbianOS Security - Code Security
  •  iPhone Application Development : Getting the User’s Attention - Generating Alerts
  •  iPhone Application Development : Getting the User’s Attention - Exploring User Alert Methods
  •  iPhone Application Development : Using Advanced Interface Objects and Views - Using Scrolling Views
  •  Working with the Windows Phone 7 Application Life Cycle (part 2) - Managing Application State
  •  Working with the Windows Phone 7 Application Life Cycle (part 1) - Observing Application Life Cycle Events
  •  Mobile Application Security : SymbianOS Security - Development and Security Testing
  •  Mobile Application Security : SymbianOS Security - Introduction to the Platform
  •  Java Mobile Edition Security : Permissions and User Controls
  •  Integrating Applications with the Windows Phone OS : Working with Launchers and Choosers
  •  Introducing Windows Phone 7 Launchers and Choosers
  •  Java Mobile Edition Security : Development and Security Testing (part 3) - Code Security & Application Packaging and Distribution
  •  Java Mobile Edition Security : Development and Security Testing (part 2) - Reverse Engineering and Debugging
  •  Java Mobile Edition Security : Development and Security Testing (part 1) - Configuring a Development Environment and Installing New Platforms & Emulator
  •  Java Mobile Edition Security : Configurations, Profiles, and JSRs
  •  Programming the Mobile Web : Performance Optimization
  •  Programming the Mobile Web : Testing and Debugging (part 3) - Client-Side Debugging
  •  Programming the Mobile Web : Testing and Debugging (part 2) - Server-Side Debugging & Markup Debugging
  •  Programming the Mobile Web : Testing and Debugging (part 1) - Remote Labs
    Top 10
    Windows Vista Services that You Need Understand
    Advanced ASP.NET : Data Caching (part 2) - Caching to Provide Multiple Views
    Windows Phone 7 Development : Internationalization - Using Resource Files to Localize Content
    Tools to Manage Access Control Lists
    Windows Phone 7 Development : Using GeoCoordinateWatcher and the Bing Maps Control to Track Your Movements
    Programming with DirectX : Textures in Direct3D 10 (part 2)
    Windows Azure : Understanding the Blob Service
    iPhone 3D Programming : Adding Depth and Realism - Lighting Up (part 1)
    Sharepoint 2007: Get Started with Your Personal Site
    ASP.NET 4 in VB 2010 : The Security Controls
    Most View
    Windows Server 2003 : Installing and Configuring Domain Controllers
    Exchange Server 2007: Design and Deploy Disaster Recovery Settings - Implement Database Portability
    SQL Server 2005 : Exception Handling
    Mobile Application Security : The Apple iPhone - Permissions and User Controls
    IIS 7.0 : Configuring IIS Logging
    Windows 7 : Maintaining and Recovering Volumes
    Exchange Server 2010 : Implementing Client Access and Hub Transport Servers - Understanding the Hub Transport Server
    iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 3)
    Windows 7 : Managing Security
    iPhone 3D Programming : Textures and Image Capture - Creating Textures with the Camera
    SQL Server 2008 : Performing Nonlogged DML Operations
    Forget About the Perimeter
    Mobile Application Security : SymbianOS Security - Development and Security Testing
    Defensive Database Programming with SQL Server : TRY...CATCH Gotchas (part 1) - Re-throwing errors
    Android Permissions Review
    Windows Phone 7 Development : Using Rx.NET with Web Services to Asynchronously Retrieve Weather Data
    MySQL Server Monitoring (part 1) - SQL Commands
    Managing the Cache
    Programming Symmetrical Encryption (part 1)
    Getting Started with Device Manager