Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a deep link of my application from the Windows Phone Marketplace using .NET code?

How do I get a deep link of my application programmatically from the Windows Phone Marketplace, so that I can use it in my code?

like image 531
krrishna Avatar asked Dec 26 '22 13:12

krrishna


1 Answers

Getting the AppDeeplink is quite useful for example in ShareStatusTask and ShareLinkTask.
It is possible, however you have to use some non-trivial code for getting the real AppID from within your app Manifest file. Here's what I do:
First save somewhere in resources the string for Windows Phone app deeplinks, this is simple:

"http://windowsphone.com/s?appId={0}"

Then you have to find the real AppId by opening the App Manifest file and finding the proper tag, I use this code inside my MarketplaceHelper for doing so:

static MarketplaceHelper()
{
    try
    {
        // load product details from WMAppManifest.xml
        XElement app = XElement.Load("WMAppManifest.xml").Descendants("App").Single();

        Title = GetValue(app, "Title");
        Version = new Version(GetValue(app, "Version"));
        Author = GetValue(app, "Author");
        Publisher = GetValue(app, "Publisher");
        Description = GetValue(app, "Description");

        // remove the surrounding braces
        string productID = GetValue(app, "ProductID");
        ProductID = Regex.Match(productID, "(?<={).*(?=})").Value;
    }
    catch (Exception e)
    {
        // should not happen, every application has this field and should containt the ProductID and Version
    }
}

private static string GetValue(XElement app, string attrName)
{
    XAttribute at = app.Attribute(attrName);
    return at != null ? at.Value : null;
}

If the Manifest is there and is properly formatted, and it should be, otherwise the app won't work, you can get this way any data you want.

Now you can construct the deeplink like this:

string deeplink = string.Format(AppResources.DeepLinkFormat, MarketplaceHelper.ProductID);
like image 59
Martin Suchan Avatar answered May 10 '23 16:05

Martin Suchan