Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Created July 21, 2020 08:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarukosu/fb25791968ddd9c0164332655c2e3db3 to your computer and use it in GitHub Desktop.
Save tarukosu/fb25791968ddd9c0164332655c2e3db3 to your computer and use it in GitHub Desktop.
Launch browser from HoloLens Unity app
using UnityEngine;
#if WINDOWS_UWP
using System;
using Windows.System;
#endif
public static class BrowserLauncher
{
public static void Launch(string url, bool useHoloBrowser = false)
{
#if WINDOWS_UWP
UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
{
try
{
var uri = new Uri(url);
if (useHoloBrowser)
{
var holoBrowserUri = new Uri($"holo-browser:{url}");
var option = new LauncherOptions()
{
FallbackUri = uri
};
await Launcher.LaunchUriAsync(holoBrowserUri, option);
}
else
{
await Launcher.LaunchUriAsync(uri);
}
}
catch (Exception e)
{
Debug.LogWarning(e);
}
}, false);
#else
Application.OpenURL(url);
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment