-api-id | -api-type | -api-device-family-note |
---|---|---|
T:Windows.System.Launcher |
winrt class |
xbox |
Starts the default app associated with the specified file or URI.
Note
This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).
Windows version | SDK version | Value added |
---|---|---|
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) |
Launch a file contained in the app package
See the code example in the LaunchFileAsync(IStorageFile) topic.
Launch a URI
See the code example in the LaunchUriAsync(Uri) topic.
Launch with a warning dialog
This example calls launchUriAsync(Uri, LauncherOptions) to launch a URI with a warning. Use the treatAsUntrusted property to indicate that the system should display a warning.
Note
For a Windows app using JavaScript, call preventDefault in your event handler if the treatAsUntrusted property is set and you are using an anchor element to launch the URI.
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
}
});
}
}
}
Launch the default app for a file, Launch the default app for a URI, Association launching sample, Guidelines for file types and URIs, LauncherOptions, LauncherUIOptions