【问题标题】:How to get a deep link of my application from the Windows Phone Marketplace using .NET code?如何使用 .NET 代码从 Windows Phone Marketplace 获取我的应用程序的深层链接?
【发布时间】:2013-04-26 01:08:12
【问题描述】:

如何以编程方式从 Windows Phone Marketplace 获取我的应用程序的深层链接,以便在我的代码中使用它?

【问题讨论】:

  • 为什么需要以编程方式获取它?

标签: windows-phone


【解决方案1】:

获取 AppDeeplink 非常有用,例如在 ShareStatusTask 和 ShareLinkTask 中。
这是可能的,但是您必须使用一些重要的代码从您的应用清单文件中获取真实的 AppID。这是我的工作:
首先将 Windows Phone 应用深层链接的字符串保存在资源中的某个位置,这很简单:

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

然后你必须通过打开 App Manifest 文件并找到正确的标签来找到真正的 AppId,我在我的 MarketplaceHelper 中使用以下代码:

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;
}

如果 Manifest 存在并且格式正确,并且应该存在,否则应用程序将无法运行,您可以通过这种方式获取所需的任何数据。

现在您可以像这样构建深层链接:

string deeplink = string.Format(AppResources.DeepLinkFormat, MarketplaceHelper.ProductID);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    相关资源
    最近更新 更多