Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 5.16 KB

get-license-info-for-apps-and-add-ons.md

File metadata and controls

50 lines (37 loc) · 5.16 KB
ms.assetid description title ms.date ms.topic keywords ms.localizationpriority
9630AF6D-6887-4BE3-A3CB-D058F275B58F
Learn how to use the Windows.Services.Store namespace to get license info for the current app and its add-ons.
Get license info for your app and add-ons
12/04/2017
article
windows 10, uwp, licenses, apps, add-ons, in-app purchases, IAPs, Windows.Services.Store
medium

Get license info for apps and add-ons

This article demonstrates how to use methods of the StoreContext class in the Windows.Services.Store namespace to get license info for the current app and its add-ons. For example, you can use this info to determine if the licenses for the app or its add-ons are active, or if they are trial licenses.

Note

The Windows.Services.Store namespace was introduced in Windows 10, version 1607, and it can only be used in projects that target Windows 10 Anniversary Edition (10.0; Build 14393) or a later release in Visual Studio. If your app targets an earlier version of Windows 10, you must use the Windows.ApplicationModel.Store namespace instead of the Windows.Services.Store namespace. For more information, see this article.

Prerequisites

This example has the following prerequisites:

  • A Visual Studio project for a Universal Windows Platform (UWP) app that targets Windows 10 Anniversary Edition (10.0; Build 14393) or a later release.
  • You have created an app submission in Partner Center and this app is published in the Store. You can optionally configure the app so it is not discoverable in the Store while you test it. For more information, see our testing guidance.
  • If you want get license info for an add-on for the app, you must also create the add-on in Partner Center.

The code in this example assumes:

  • The code runs in the context of a Page that contains a ProgressRing named workingProgressRing and a TextBlock named textBlock. These objects are used to indicate that an asynchronous operation is occurring and to display output messages, respectively.
  • The code file has a using statement for the Windows.Services.Store namespace.
  • The app is a single-user app that runs only in the context of the user that launched the app. For more information, see In-app purchases and trials.

Note

If you have a desktop application that uses the Desktop Bridge, you may need to add additional code not shown in this example to configure the StoreContext object. For more information, see Using the StoreContext class in a desktop application that uses the Desktop Bridge.

Code example

To get license info for the current app, use the GetAppLicenseAsync method. This is an asynchronous method that returns a StoreAppLicense object that provides license info for the app, including properties that indicate whether the user currently has a valid license to use the app (IsActive) and whether the license is for a trial version (IsTrial).

To access the licenses for durable add-ons of the current app for which the user has an entitlement to use, use the AddOnLicenses property of the StoreAppLicense object. This property returns a collection of StoreLicense objects that represent the add-on licenses.

[!div class="tabbedCodeSnippets"] :::code language="csharp" source="~/../snippets-windows/windows-uwp/monetize/InAppPurchasesAndLicenses_RS1/cs/GetLicenseInfoPage.xaml.cs" id="GetLicenseInfo":::

For a complete sample application, see the Store sample.

Related topics