windows-phone – 如何使用.NET代码从Windows Phone Marketplace
发布时间:2020-12-13 22:39:42 所属栏目:Windows 来源:网络整理
导读:如何从 Windows Phone Marketplace以编程方式获取我的应用程序的深层链接,以便我可以在我的代码中使用它? 解决方法 获取AppDeeplink非常有用,例如在ShareStatusTask和ShareLinkTask中. 但是,您可以使用一些非平凡的代码从应用程序清单文件中获取真正的AppID
如何从
Windows Phone Marketplace以编程方式获取我的应用程序的深层链接,以便我可以在我的代码中使用它?
解决方法
获取AppDeeplink非常有用,例如在ShareStatusTask和ShareLinkTask中.
但是,您可以使用一些非平凡的代码从应用程序清单文件中获取真正的AppID.这是我做的: 首先在资源的某处保存Windows Phone应用程序深层链接的字符串,这很简单:
然后你必须通过打开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在那里并且格式正确,它应该是,否则应用程序将无法工作,您可以通过这种方式获得您想要的任何数据. 现在你可以像这样构建deeplink: string deeplink = string.Format(AppResources.DeepLinkFormat,MarketplaceHelper.ProductID); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |