Launcher.LaunchUriAsync Launcher.LaunchUriAsync Launcher.LaunchUriAsync Launcher.LaunchUriAsync Launcher.LaunchUriAsync Method

Definition

Overloads

LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri)

Starts the default app associated with the URI scheme name for the specified URI.

LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions)

Starts the default app associated with the URI scheme name or the one specified by the ContentType for the specified URI, using the specified options.

LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet)

Starts the default app associated with the URI scheme name for the specified URI, using the specified options and input data.

LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri) LaunchUriAsync(Uri)

Starts the default app associated with the URI scheme name for the specified URI.

public : static IAsyncOperation<Platform::Boolean> LaunchUriAsync(Uri uri)
static IAsyncOperation<bool> LaunchUriAsync(Uri uri) const;
public static IAsyncOperation<bool> LaunchUriAsync(Uri uri)
Public Shared Function LaunchUriAsync(uri As Uri) As IAsyncOperation(Of bool)
Windows.System.Launcher.launchUriAsync(uri).done( /* Your success and error handlers */ );

Parameters

uri
Uri Uri Uri

The URI.

Returns

Returns true if the default app for the URI scheme was launched; false otherwise.

Examples

This example uses LaunchUriAsync(Uri) to launch a URI.

// The URI to launch
string uriToLaunch = @"http://www.bing.com";

// Create a Uri object from a URI string 
var uri = new Uri(uriToLaunch);

// Launch the URI
async void DefaultLaunch()
{
   // Launch the URI
   var success = await Windows.System.Launcher.LaunchUriAsync(uri);

   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}
// The URI to launch.
Windows::Foundation::Uri m_uri{ L"http://www.bing.com" };
...
Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Launch the URI.
    if (co_await Windows::System::Launcher::LaunchUriAsync(m_uri))
    {
        // URI launched.
    }
    else
    {
        // URI launch failed.
    }
}
// The URI to launch
auto uri = ref new Windows::Foundation::Uri("http://www.bing.com");

void MainPage::DefaultLaunch()
{
   // Launch the URI
   concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri));
   launchUriOperation.then([](bool success)
   {
      if (success)
      {
         // URI launched
      }
      else
      {
         // URI launch failed
      }
   });
}
// The URI to launch
var uriToLaunch = "http://www.bing.com";

// Create a Uri object from a URI string 
var uri = new Windows.Foundation.Uri(uriToLaunch);

// Launch the URI
Windows.System.Launcher.launchUriAsync(uri).then(   
   function (success) {
      if (success) {
        // URI launched
      } else {
        // URI launch failed
      }
   });
' The URI to launch
Dim uri As New Uri("http://www.bing.com")

async Sub DefaultLaunch()

   ' Launch the URI
   Dim success = await Windows.System.Launcher.LaunchUriAsync(uri)

   If success Then
      ' URI launched
   Else
      ' URI launch failed
   End If

End Sub

Remarks

Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as the UI thread).

This API may also be called from a Windows desktop application.

This API launches the default app for the scheme whether it be a Universal Windows Platform (UWP) app or Windows desktop application.

The calling app must be visible to the user when the API is invoked.

You must specify the privateNetworkClientServer capability in the manifest in order to launch intranet URIs, for example a file:/// URI pointing to a network location.

You cannot use this method to launch a URI in the local zone. For example, apps cannot use the file:/// protocol to access files on the local computer. Instead, you must use the Storage APIs to access files.

When the launch fails for any of the above reasons, the API will succeed and return FALSE from its asynchronous operation.

To enable the user to choose an app instead of launching the default app, set the LauncherOptions.DisplayApplicationPicker property.

To display a warning that the URI is potentially unsafe, set the LauncherOptions.TreatAsUntrusted property.

The URI is passed to the associated app. If the associated app is a desktop app, the URI is passed using shell execution mechanisms.

See also

LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions) LaunchUriAsync(Uri, LauncherOptions)

Starts the default app associated with the URI scheme name or the one specified by the ContentType for the specified URI, using the specified options.

public : static IAsyncOperation<Platform::Boolean> LaunchUriAsync(Uri uri, LauncherOptions options)
static IAsyncOperation<bool> LaunchUriAsync(Uri uri, LauncherOptions options) const;
public static IAsyncOperation<bool> LaunchUriAsync(Uri uri, LauncherOptions options)
Public Shared Function LaunchUriAsync(uri As Uri, options As LauncherOptions) As IAsyncOperation(Of bool)
Windows.System.Launcher.launchUriAsync(uri, options).done( /* Your success and error handlers */ );

Parameters

uri
Uri Uri Uri

The URI.

options
LauncherOptions LauncherOptions LauncherOptions

The launch options for the app.

Returns

Returns true if the default app for the URI scheme was launched; false otherwise.

Examples

This sample uses LaunchUriAsync(Uri, LauncherOptions) to launch a URI with a warning. The TreatAsUntrusted property indicates that the system should display a warning.

// The URI to launch
string uriToLaunch = @"http://www.bing.com";
var uri = new Uri(uriToLaunch);

async void DefaultLaunch()
{
   // Set the option to show a warning
   var options = new Windows.System.LauncherOptions();
   options.TreatAsUntrusted = true;

   // Launch the URI with a warning prompt
   var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);

   if (success)
   {
      // URI launched
   }
   else
   {
      // URI launch failed
   }
}
// The URI to launch.
Windows::Foundation::Uri m_uri{ L"http://www.bing.com" };

Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Set the option to show a warning
    Windows::System::LauncherOptions launcherOptions;
    launcherOptions.TreatAsUntrusted(true);

    // Launch the URI.
    if (co_await Windows::System::Launcher::LaunchUriAsync(m_uri, launcherOptions))
    {
        // URI launched.
    }
    else
    {
        // URI launch failed.
    }
}
// The URI to launch
auto uri = ref new Windows::Foundation::Uri("http://www.bing.com");

void MainPage::DefaultLaunch()
{
   // Set the option to show a warning
   auto launchOptions = ref new Windows::System::LauncherOptions();
   launchOptions->TreatAsUntrusted = true;

   // Launch the URI with a warning prompt
   concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri, launchOptions));
   launchUriOperation.then([](bool success)
   {
      if (success)
      {
         // URI launched
      }
      else
      {
         // URI launch failed
      }
   });
}

Note

For Windows app using JavaScript, call preventDefault in your event handler if the treatAsUntrusted property is set and you are using an a element to launch the URI.

// The URI to launch
var uriToLaunch = "http://www.bing.com";

// Create a Uri object from a URI string 
var uri = new Windows.Foundation.Uri(uriToLaunch);

// Launch the URI with a warning prompt
var options = new Windows.System.LauncherOptions();
options.treatAsUntrusted = true;

Windows.System.Launcher.launchUriAsync(uri, options).then(
   function (success) {
      if (success) {
         // URI launched
      } else {
         // URI launch failed
      }
   });
' The URI to launch
Dim uri As New Uri("http://www.bing.com")

async Sub DefaultLaunch()

   ' Set the option to show a warning
   Dim options = Windows.System.LauncherOptions()
   options.TreatAsUntrusted = True

   ' Launch the URI with a warning prompt
   Dim success = await Windows.System.Launcher.LaunchUriAsync(uri, options)

   If success Then
      ' URI launched
   Else
      ' URI launch failed
   End If

End Sub

Remarks

Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as the UI thread).

This API may also be called from a Windows desktop application.

This API launches the default app for the scheme whether it be a Universal Windows Platform (UWP) app or Windows desktop application.

The calling app must be visible to the user when this API is invoked.

Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as a UI thread).

You must specify the privateNetworkClientServer capability in the manifest in order to launch intranet URIs, for example a file:/// URI pointing to a network location.

You cannot use this method to launch a URI in the local zone. For example, apps cannot use the file:/// protocol to access files on the local computer. Instead, you must use the Storage APIs to access files.

The content type is used to compute a file extension, from the extension the default app is chosen. For example a content type value of ""application/vnd.ms-word.document.12"" is mapped to ".docx" and then the default application for ".docx" is launched. For example:


// this specifies the file type, which is used to bind to Word. 
launcherOptions.ContentType = "application/vnd.ms-word.document.12"; 
// and then this launches the file using the application
Launcher.LaunchUriAsync("http://www.cloud.com/file.docx", options);

When the launch fails for any of the above reasons, the API will succeed and return FALSE from its asynchronous operation.

To enable the user to choose an app instead of launching the default app, set the LauncherOptions.DisplayApplicationPicker property.

To display a warning that the URI is potentially unsafe, set the LauncherOptions.TreatAsUntrusted property.

The URI is passed to the associated app. If the associated app is a desktop app, the URI is passed using shell execution mechanisms.

See also

LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet) LaunchUriAsync(Uri, LauncherOptions, ValueSet)

Starts the default app associated with the URI scheme name for the specified URI, using the specified options and input data.

public : static IAsyncOperation<Platform::Boolean> LaunchUriAsync(Uri uri, LauncherOptions options, ValueSet inputData)
static IAsyncOperation<bool> LaunchUriAsync(Uri uri, LauncherOptions options, ValueSet inputData) const;
public static IAsyncOperation<bool> LaunchUriAsync(Uri uri, LauncherOptions options, ValueSet inputData)
Public Shared Function LaunchUriAsync(uri As Uri, options As LauncherOptions, inputData As ValueSet) As IAsyncOperation(Of bool)
Windows.System.Launcher.launchUriAsync(uri, options, inputData).done( /* Your success and error handlers */ );

Parameters

uri
Uri Uri Uri

The URI.

options
LauncherOptions LauncherOptions LauncherOptions

The launch options for the app.

inputData
ValueSet ValueSet ValueSet

The input data for the app.

Important

The amount of data that can be transferred must not exceed 100 KB.

Returns

Returns true if the default app for the URI scheme was launched; false otherwise.

Remarks

Unless you are calling this API from a Windows desktop application, this API must be called from within an ASTA thread (also known as the UI thread).

This API may also be called from a Windows desktop application.

This API launches the default app for the scheme whether it be a Universal Windows Platform (UWP) app or Windows desktop application.

See also