How to check if an add-on has purchased that use StoreContext class

Fei Xue - MSFT 1,111 Reputation points
2019-10-30T06:32:31.537+00:00

I have defined a durable AddOn, and when I used RequestPurchaseAsync() method to check if an add-on has purchased or not, it always shows UI which will be annoying to the user.

In the previous version I used: CurrentApp.LicenseInformation.ProductLicenses[ProductId].IsActive to check if the add-on has purchased. So is there any method in StoreContext to solve the problem?

Developer technologies | Universal Windows Platform (UWP)

Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2019-10-31T01:21:43.987+00:00

Hello,

Welcome to our Microsoft Q&A platform!

In order to check if an add-on has purchased or not, please check the license information using StoreContext Class. 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 as follows:

public async void GetLicenseInfo()  
{  
    if (context == null)  
    {  
        context = StoreContext.GetDefault();  
    }  
    StoreAppLicense appLicense = await context.GetAppLicenseAsync();  
  
    if (appLicense == null)  
    {  
        textBlock.Text = "An error occurred while retrieving the license.";  
        return;  
    }  
  
    // Access the valid licenses for durable add-ons for this app.  
    foreach (KeyValuePair item in appLicense.AddOnLicenses)  
    {  
        StoreLicense addOnLicense = item.Value;  
        // Use members of the addOnLicense object to access license info  
        // for the add-on.  
    }  
}  

For more information, please refer to this document: Get license info for apps and add-ons.

Thanks

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more