Launcher 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
启动与指定文件或 URI 关联的默认应用。
public ref class Launcher abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class Launcher final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Launcher final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public static class Launcher
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class Launcher
Public Class Launcher
- 继承
- 属性
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
示例
启动应用包中包含的文件
请参阅 LaunchFileAsync (IStorageFile) 主题中的代码示例。
启动 URI
请参阅 LaunchUriAsync (Uri) 主题中的代码示例。
使用警告对话框启动
此示例调用 launchUriAsync (Uri,LauncherOptions) 以启动带有警告的 URI。 使用 treatAsUntrusted 属性指示系统应显示警告。
注意
对于使用 JavaScript 的 Windows 应用,如果设置了 treatAsUntrusted 属性,并且使用定位点元素启动 URI,请在事件处理程序中调用 preventDefault。
function linkClickHandler(eventInfo) {
var link = eventInfo.target;
if (eventInfo.srcElement && (
(eventInfo.type === "click") ||
(eventInfo.type === "keydown" && (
eventInfo.keyCode === WinJS.Utilities.Key.enter ||
eventInfo.keyCode === WinJS.Utilities.Key.space)))) {
eventInfo.preventDefault();
if (link.href.indexOf("ms-appx") > -1) {
WinJS.Navigation.navigate(link.href);
}
else if (link.href.indexOf("http") > -1) {
// Create a Uri object from a URI string
var uri = new Windows.Foundation.Uri(link.href);
var options = new Windows.System.LauncherOptions();
// Launch the URI with a warning prompt
options.treatAsUntrusted = true;
// Launch the URI
Windows.System.Launcher.launchUriAsync(uri, options).then(
function (success) {
if (success) {
// URI launched
} else {
// URI launch failed
}
});
}
}
}
注解
注意
此类不敏捷,这意味着需要考虑其线程模型和封送处理行为。 有关详细信息,请参阅线程和封送处理 (C++/CX) 和使用多线程环境中的Windows 运行时对象 (.NET) 。
版本历史记录
Windows 版本 | SDK 版本 | 已添加值 |
---|---|---|
1607 | 14393 | FindAppUriHandlersAsync |
1607 | 14393 | LaunchUriForResultsForUserAsync (User,Uri,LauncherOptions) |
1607 | 14393 | LaunchUriForResultsForUserAsync (User,Uri,LauncherOptions,ValueSet) |
1607 | 14393 | LaunchUriForUserAsync (User,Uri) |
1607 | 14393 | LaunchUriForUserAsync (User,Uri,LauncherOptions) |
1607 | 14393 | LaunchUriForUserAsync (User,Uri,LauncherOptions,ValueSet) |
1607 | 14393 | QueryAppUriSupportAsync (Uri) |
1607 | 14393 | QueryAppUriSupportAsync (Uri,String) |
1809 | 17763 | LaunchFolderPathAsync (String) |
1809 | 17763 | LaunchFolderPathAsync (String,FolderLauncherOptions) |
1809 | 17763 | LaunchFolderPathForUserAsync (User,String) |
1809 | 17763 | LaunchFolderPathForUserAsync (User,String,FolderLauncherOptions) |