MOBILE

Windows Phone 7 Development : Understanding Trial and Full Modes (part 2) - Using the Marketplace APIs

2/19/2011 5:44:48 PM

2. Using the Marketplace APIs

Now that you know how to find out whether an application is running in trial mode, let's add the ability to review an application and buy it. To do that, you'll need two new classes found in the Microsoft.Phone.Tasks namespace: MarketplaceDetailTask and MarketplaceReviewTask. These classes, known as application launchers on the Windows Phone 7 platform, contain all the necessary functionality for your application to switch from trial to full mode.

Both MarketplaceDetailTask and MarketplaceReviewTask classes implement a Show method that launches the Windows Phone Marketplace application and navigates to the specified application page. For the purposes of allowing users to switch from trial license to full license, there is little difference between these two classes. However, for reference purposes, note that MarketplaceDetailTask allows an application developer to specify an ID of the application (in the ContentIdentifier property) to show the Windows Phone Marketplace page for. This application ID is optional—if it's not supplied to the MarketplaceDetailTask class, the details for the current application are shown in the Marketplace. The MarketplaceReviewTask class, on the other hand, does not expose any public properties, and its Show method displays the review page with an option to buy for the current application only.

Let's enhance the TrialSample application created in the previous walkthrough with an option to review and buy the application from the Windows Phone Marketplace. We will enhance the code so that if an application is executing in the trial mode, it will show two buttons—one with an option to "Upgrade to Full Version" and another with an option to "Cancel" and return to the main screen.

Follow these steps to complete these enhancements. First, you'll add the new namespace reference that contains the APIs you need, and then add the two new buttons:

  1. Launch Visual Studio 2010 Express for Windows Phone if it is not already open, and open the Windows Phone Application project called "TrialSample" created during the previous walkthrough.

  2. Add the following statement to the top of the page:

    using Microsoft.Phone.Tasks;

  3. From the Toolbox, drag and drop a button onto the design surface directly beneath the textBlock1 control, as shown in Figure 2. With that button selected, press F4 to bring up the button properties window, change the button's Content property to "Upgrade to Full Version," and set the button's Visibility property to "Collapsed." Change the button's name to "btnUpgrade."

  4. From the Toolbox, drag another button onto the design surface and drop it next to btnUpgrade, as shown in Figure 2. With that button selected, press F4 to bring up the button properties window and change the button's Content property to "Cancel." Change the button's Visibility property to "Collapsed." Change the button's name to "btnCancel." You should now end up with a design surface resembling Figure 2.

Next, you need to add code that responds to the new buttons.

Figure 2. TrialSample application layout

  1. Double-click the Upgrade to Full Version button and change the btnUpgrade_Click method to the following:

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


  2. In MainPage.xaml.cs, change the MainPage() constructor to the following:

    public MainPage()
    {
    InitializeComponent();

    LicenseInformation lic = new LicenseInformation();
    if (lic.IsTrial() == true)
    {
    textBlock1.Text = "You are running a trial version of our software!";
    btnUpgrade.Visibility = Visibility.Visible;



    btnCancel.Visibility = Visibility.Visible;
    }
    else
    {
    textBlock1.Text = "Thank you for using the full version of our software!";
    }
    }


When you press F5 to run the application now, there are two issues that immediately jump out at you. First, the IsTrial method, in its current implementation within Windows Phone 7 Framework, always returns false to the emulator. Because of this, given the logic of the application's current implementation, you will not see the buttons with options to upgrade to the full version of an application. If you try to force those buttons to appear, by incorrectly changing the if (lic.IsTrial() == true)if (lic.IsTrial() == false), for example, then when you click the Upgrade to Full Version button, a second issue surfaces. Since the application has not been approved and is not even registered with Windows Phone Marketplace, you will get an error (as expected) trying to display the application details page. statement to

For details on the Windows Phone Marketplace registration and application approval process. Here, let's assume that once the proper application registration is in place, Windows Phone Marketplace will properly display the application details page using the MarketplaceReviewTask class and then swap the trial license and a full application license if the user decides to purchase the program. That still leaves us with the need to properly test the application using both trial and full license modes before submitting the application to the Marketplace to ensure that all functionality that belongs to the full mode only is not available to trial users. The process of simulating trial application mode is the subject of the next section.

Other  
  •  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
    Sapphire Pure Platinum A85XT - Sensible Smattering Of Features
    SSD Supertest – December 2012 (Part 6)
    SSD Supertest – December 2012 (Part 5) : Samsung 840 250GB, Samsung 840 Pro 256GB
    SSD Supertest – December 2012 (Part 4) : OCZ Vertex 4 256GB, Plextor M5 Pro 128GB
    SSD Supertest – December 2012 (Part 3) : KingSpec PCIe MultiCore 1TB, Kingston HyperX 3K 120GB
    SSD Supertest – December 2012 (Part 2) : Intel 330 Series 180GB
    SSD Supertest – December 2012 (Part 1) : Corsair Neutron 240GB, Corsair Neutron GTX 240GB
    Synology DS213+ - Great Features, But Expensive
    Thermaltake Level 10m - The BMW Gaming Mice
    ZOTAC GTX 650 TI – It’s Time To Play
    Most View
    Asus X501A - Thin And Light Design For Your Personal Expression
    Personalize Your iPhone Case
    SharePoint 2010 : Outlining the Inherent Threat in SharePoint Web Traffic
    Displacement Maps
    Google’s Data Liberation Front (Part 2)
    The big test … Inter Core Power (Part 2) - Asus Zenbook UX31E & Dell XPS 14z
    How To Automate Your Web With ifttt (Part 1)
    HP Photosmart 5510 e-All-in-One Printer
    OData with SQL Azure - Enabling OData on an Azure Database
    Algorithms for Compiler Design: DATA STRUCTURES FOR REPRESENTING PARSING TABLES
    Recommended Buys: Everyday Computing – November 2012
    Asus X53z
    The New Sheriff In Town
    Which Is The Real Best-Seller Ultrabook? (Part 1) - Asus Zenbook Prime, Acer Aspire S5, HP Folio 13-2000
    Exchange Server 2007: Design and Deploy Disaster Recovery Settings - Implement Database Portability
    Gioteck HF-2 Controller - Different Strokes
    Managing Exchange Server 2010 : The Exchange Management Shell (part 2) - Remote PowerShell
    The Pick Of Windows 8 Metro Apps (Part 2)
    HP Global Influencer Summit 2012 (Part 2) - HP Photosmart 5520 e All-in-One, HP t410 AIO
    Google’s Data Liberation Front (Part 1)