我需要使用 URI 从 Microsoft Store 启动应用程序。游戏栏小部件允许您仅使用
widget.LaunchUriAsync(uri)
启动应用程序
我可以使用
PackageManager
获取已安装软件包的列表,但 AppInfo
和 Package
中没有 URI。
如何获取从 Microsoft Store 安装的应用程序的 URI?不考虑标准
ms-settings:
ms-photos:
以及其他
我尝试使用
GetFromAppUserModelId(AUMID).Package.GetAppInstallerInfo().Uri
,但它返回null
HKEY_CLASSES_ROOT\Extensions\ContractId\Windows.Protocol\PackageId
,但是 UWP 无权访问注册表
在这里找到答案。
var file = await AppInfo.GetFromAppUserModelId(AUMDI).Package.InstalledLocation.GetFileAsync("AppxManifest.XML");
using (Stream stream = await file.OpenStreamForReadAsync())
{
var doc = XDocument.Load(stream);
var docXml = new XmlDocument();
docXml.LoadXml(doc.ToString());
var tags = docXml.GetElementsByTagName("uap:Protocol");
if (tags.Count > 0)
{
var firstContent = tags[0];
string result = firstContent.Attributes.GetNamedItem("Name").InnerText;
Debug.WriteLine(result);
Uri uri = new Uri(result + @"://");
if (parent.widget != null) { await parent.widget.LaunchUriAsync(uri); } else { await Launcher.LaunchUriAsync(uri); }
}
}