- 1 year ago
Open Microsoft Edge while running app in Hololens
In a Microsoft HoloLens app, you can use the Launcher
class from the Windows Runtime API to open Microsoft Edge (or any other external application) programmatically. The Launcher
class provides methods to launch various file types and protocols, including opening URLs in the default web browser, which, in the case of HoloLens, is Microsoft Edge.
Here's how you can open Microsoft Edge in a HoloLens app using C# and the Launcher
class:
Add Reference:
Make sure your Visual Studio project references theWindows
namespace.Import Namespaces:
In your C# code, import the required namespaces:csharpusing System;
using Windows.System;
Open Microsoft Edge:
To open Microsoft Edge with a specific URL, use theLauncher.LaunchUriAsync
method:csharpprivate async void OpenEdgeButton_Click(object sender, RoutedEventArgs e)
{
// Replace "https://www.example.com" with the URL you want to open in Microsoft Edge
string urlToOpen = "https://www.example.com";
// Create a Uri object with the URL
Uri uri = new Uri(urlToOpen);
// Launch Microsoft Edge with the specified URL
var success = await Launcher.LaunchUriAsync(uri);
if (success)
{
// The URL was opened successfully in Microsoft Edge
// Add any additional logic here if needed
}
else
{
// Failed to open the URL in Microsoft Edge
// Handle the failure scenario here if needed
}
}
UI Interaction:
In your app, you can trigger theOpenEdgeButton_Click
method when the user interacts with a button or other UI element, such as through voice commands or gestures.
This code will open Microsoft Edge on the HoloLens with the specified URL. Please note that if the HoloLens is not connected to the internet or if Microsoft Edge is not installed on the device, the operation might fail. It's a good practice to handle any error scenarios and provide appropriate feedback to the user.
Ensure that your HoloLens app has the necessary permissions to access the internet and launch external applications. If you are deploying the app through the Microsoft Store, review the store certification requirements to ensure compliance.