#WPdev Quick tip – API for accessing Windows Store from your app

Following the previous WPdev quick tip how to initiate Email Compose from your app, here is another API that developer often need:

  • Navigate to Rate and Review dialog for the current app – if you want to initiate app rating from the current user
  • Navigate to Windows/Phone Store to the currently running app – if you want the user to purchase full version of current app or upgrade to a new version
  • Navigate to Windows/Phone Store to all apps published by the current developer – if you want to encourage the user to download other of your apps

Unfortunately all these tasks require different type of API in Windows Phone 7.5/8/8.1 Silverlight apps, in Windows 8.1 apps and another one in Windows Phone 8.1 WinRT apps and since I needed all these methods in my recent Windows Universal App NASA TV Live, I decided to put it all into short article for future use, so here it is:

Windows Phone 7, 7.5, 8 and 8.1 (Silverlight)

Navigating to Review dialog and navigating to various Store pages is in Windows Phone Silverlight apps done using so called tasks. The usage of all these tasks is quite straightforward – you just need to create specific task, set required properties and call Show().

// Navigate to Rate and Review dialog for the current app
MarketplaceReviewTask reviewTask = new MarketplaceReviewTask();
reviewTask.Show();
 
// Navigate to Windows Phone Store to the currently running app
MarketplaceDetailTask marketplaceDetail = new MarketplaceDetailTask
{
    ContentType = MarketplaceContentType.Applications
};
marketplaceDetail.Show();
 
// Navigate to Windows Phone Store to all apps published by the current developer
MarketplaceSearchTask marketplaceSearch = new MarketplaceSearchTask
{
    SearchTerms = "Martin Suchan"
};
marketplaceSearch.Show();

Note using the MarketplaceSearchTask it’s also possible to search for apps with specific name using SearchTerms = “app name”, and using MarketplaceDetailTask you can search for specific app detail by providing ContentIdentifier = “app-guid”. The documentation for all these tasks is available on MSDN.

The bottom line is – easy to use and type safe API.

Windows 8 and 8.1

Just like in my previous article, you cannot use the Silverlight API in Windows 8.1 or Windows Phone 8.1 apps. Luckily there is again Uri scheme based alternative for navigating to Windows Store pages.

// Navigate to Rate and Review dialog for the current app
Uri uri1 = new Uri(string.Format("ms-windows-store:Review?PFN={0}", Package.Current.Id.FamilyName));
await Launcher.LaunchUriAsync(uri1);
 
// Navigate to Windows Store to the currently running app
Uri uri2 = new Uri(string.Format("ms-windows-store:PDP?PFN={0}", Package.Current.Id.FamilyName));
await Launcher.LaunchUriAsync(uri2);
 
// Navigate to Windows Store to all apps published by the current developer
Uri uri3 = new Uri(string.Format("ms-windows-store:Publisher?name={0}", "Martin Suchan"));
await Launcher.LaunchUriAsync(uri3);

The PFN in these snippets refer to the Package Family Name, unique app id composed of your developer account Id and unique app Id. You can find this PFN either in you Developer Dashboard when submitting the app, or in the Package.appxmanifest file once the app is associated with the Store. It’s also possible to get this name programatically directly in your app using Package.Current.Id.FamilyName.

There are other methods available as well when navigating to the Windows Store using ms-windows-store Uri scheme. Full documentation of this Windows 8.1 Uri scheme is located deep inside MSDN and it actually took me a while to find it, when I needed it for my recent app.

Windows Phone 8.1 (WinRT)

In Windows Phone 8.1 Universal apps we need to use, again, even another API for accessing the Store pages. This time we use ms-windows-store Uri scheme just like in Windows 8.1 apps, but we need to use different query strings to reach the target pages.

// Navigate to Rate and Review dialog for the current app
Uri uri1 = new Uri(string.Format("ms-windows-store:reviewapp?appid={0}", CurrentApp.AppId));
await Launcher.LaunchUriAsync(uri1);
 
// Navigate to Windows Phone Store to the currently running app
Uri uri2 = new Uri(string.Format("ms-windows-store:navigate?appid={0}", CurrentApp.AppId));
await Launcher.LaunchUriAsync(uri2);
 
// Navigate to Windows Phone Store to all apps published by the current developer
Uri uri3 = new Uri(string.Format("ms-windows-store:search?keyword={0}", "Martin Suchan"));
await Launcher.LaunchUriAsync(uri3);

The appid in this case refers to unique Windows Phone app Guid. This Guid is available again either in the Developer Dashboard or can be accessed programatically using the CurrentApp.AppId property.

Full documentation of the ms-windows-store Uri scheme for Windows Phone 8.1 apps with more examples and available query strings is available on MSDN.

The future in Windows 10

It’s expected that in Windows 10 Universal App API you’d need to use only one Uri scheme for navigating to the Store in both Windows, Phone and even in Xbox apps. It’s also possible that there will be new Strongly typed API available for these tasks, that would be easier to use than the current one error-prone approach, where you need to manually compose Uris.

For the time being, you just need to create one big StoreHelper with lot of #if #elif conditional statements, or one IStoreService interface with different per-platform implementation.