I'm trying to open a PDF within a Unity app deployed to a Microsoft Hololens 2 using the MRTK. I want to use the integrated Edge Browser, that is able to load within the app and to run simulatenously. Edge by itself is also able to load pdf files. I expected using LaunchUri would open the file from a provided location
public void Launch()
{
var absolutePath = Path.Combine(_myDocuments, _subfolder);
absolutePath = Path.Combine(absolutePath, _fileName);
#if UNITY_WSA
UnityEngine.WSA.Launcher.LaunchUri(absolutePath, true);
#else
Application.OpenURL(absolutePath);
#endif
}
Launching the Edge Browser with a website as the string, works. Entering the file path manually into the browser window to load the pdf also works, but launching the Browser by directly providing the full path to my file, does not open any browser window. I suspect, that it doesn't work because Edge is not setup to be the default app for PDF files, but when using the button within Edge to make it the default app, it just tells me that it failed and I can't find any other way to achieve that. Does anyone else have an idea how I would be able to load Edge from within an Unity app and providing the path to my pdf file so it automatically loads on a button press?
The PDF is stored on the local file system under "Documents". As mentioned, the file is accessible and can be opened by Edge. Using the system File Browser to manually open the PDF from within the system automatically uses Edge and opens the file as expected, which is the behaviour I would like to copy from within Unity.
Environment
edit: I ended up using
UnityEngine.WSA.Launcher.LaunchFile(folderType, relativePath, false);
You can try Launcher.LaunchFileAsync to launch a PDF file with Edge. This method required a StorageFile as the parameter, which can be got by FileOpenPicker or GetFileFromPathAsync.
Please refer to the following code.
private async void PickAndLaunchFile()
{
// First, get a file via the picker.
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.FileTypeFilter.Add("*");
Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Next, launch the file.
bool success = await Launcher.LaunchFileAsync(file);
}