ailon's DevBlog: Development related stuff in my life

Launching Windows Store from your Metro style app

7/13/2012 3:03:44 PM

Suppose you wanted to include a page in your new shiny Windows 8 Metro app listing your other apps and when a user taps on an app in the list he/she will be immediately transferred into Windows Store to give you more money (or at least boost your rankings). How do you do that?

In Windows Phone that was really easy. There was a MarketplaceDetailTask class just for that. So you would do something like this:

MarketplaceDetailTask mpTask = new MarketplaceDetailTask();
mpTask.ContentIdentifier = marketplaceAppId;


But there’s nothing like that in WinRT. As it usually happens with advanced APIs simplicity was sacrificed in the name of flexibility. In Windows 8 any app can register (with user’s permission) as a default app to handle some protocol. So Windows Store is no different. It’s a default app to handle “ms-windows-store” protocol. You can read more on the protocol here.

So you need to construct a URI, create an instance of Windows.System.Launcher and call LaunchUriAsync(uri). Here’s a tutorial on how to do this for a general abstract case.

So the structure of URI for ms-windows-store protocol looks like this:


Where PFN stands for Package Family Name which is sort of an equivalent of marketplace id of your app in Windows Store. If it’s for your own app you can get it in Visual Studio or web version of your apps listing in the store as detailed in this post. If it’s not your app the web version is your only choice and (to make things more complicated) it’s not browsable or searchable at the time of this writing. So the only way to get it is if developers posted a link to it on their web page (let me know in the comments if you know other ways).

Developers of the awesome twitter client Metrotwit did just that and we can browse to their web listing and view source of that page.


So we now have everything we need and the C# code to launch a Windows Store for Metrotwit from within your Metro style app looks like this:

var storeURI = new Uri("ms-windows-store:PDP?PFN=PixelTuckerPtyLtd.MetroTwit_5kbmb3e034y6r");
await Windows.System.Launcher.LaunchUriAsync(storeURI);

It’s not too difficult to create a Windows Phone style wrapper for this if you wish to do it “old school” way.


blog comments powered by Disqus
Copyright © 2003 - 2018 Alan Mendelevich
Powered by BlogEngine.NET