我想将Edge浏览器中的内容共享到我的应用程序中(当我的应用程序处于最小化状态时)。但是,它不起作用。LaunchUriAsync未还原应用程序窗口。可能的原因,应用程序在后台任务中运行,这就是为什么UI操作无法正常工作的原因?
有人可以提出任何解决方案吗?
当应用程序处于最小化状态时如何从边缘浏览器共享到UWP应用程序C#uwp
通常,您可以打开已注册的UWP应用,以成为统一资源标识符(URI)方案名称的默认处理程序。然后,我们可以将应用程序的启动uri添加到html页面中,以供浏览器使用,如下所示。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App36</title>
<link href="css/default.css" rel="stylesheet" />
</head>
<body>
<div>Content goes here!</div>
<div>
<a href="ms-windows-store:">OpenApp</a>
</div>
<script src="js/main.js"></script>
</body>
</html>
当您在Windows 10操作系统中运行的浏览器中单击OpenApp标签时,它将启动商店应用程序。您可以将ms-windows-store:替换为您的应用Uri协议名称(例如:myapp :),以启动您的应用并根据您的设计传递参数。
在UWP客户端中,我们需要在OnActivated
方法中处理来自浏览器的共享参数并Window.Current.Activate()
最终调用。
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
// Navigate to a view
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
Window.Current.Content = rootFrame;
}
// assuming you wanna go to MainPage when activated via protocol
rootFrame.Navigate(typeof(MainPage), eventArgs);
}
Window.Current.Activate();
}
有关更多详细信息,请处理URI激活。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句