Search Unity

Question How to call LaunchUriForResultsAsync in Unity for HoloLens

Discussion in 'AR' started by ctswearableglass3, Jan 29, 2021.

  1. ctswearableglass3

    ctswearableglass3

    Joined:
    Feb 28, 2020
    Posts:
    1
    From the HoloLens, need to launch another UWP app, like app to app communications. We can get the results from the launching app to calling app using LaunchUriForResultsAsync (Windows API).

    This API must be called from within an ASTA thread (also known as a UI thread). Pease find the below link as well
    https://docs.microsoft.com/en-us/uw...her.launchuriforresultsasync?view=winrt-19041

    Code (CSharp):
    1. async Task<string> LaunchAppForResults()
    2. {
    3.     var testAppUri = new Uri("test-app2app:"); // The protocol handled by the launched app
    4.     var options = new LauncherOptions();
    5.     options.TargetApplicationPackageFamilyName = "67d987e1-e842-4229-9f7c-98cf13b5da45_yd7nk54bq29ra";
    6.  
    7.     var inputData = new ValueSet();
    8.     inputData["TestData"] = "Test data";
    9.  
    10.     string theResult = "";
    11.     LaunchUriResult result = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options, inputData);
    12.     if (result.Status == LaunchUriStatus.Success &&
    13.         result.Result != null &&
    14.         result.Result.ContainsKey("ReturnedData"))
    15.     {
    16.         ValueSet theValues = result.Result;
    17.         theResult = theValues["ReturnedData"] as string;
    18.     }
    19.     return theResult;
    20. }
    using #ENABLE_WINMD_SUPPORT used the above method to run in HoloLens, throws exception that This API needs to be run on UI Thread. How we can achieve this.
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  3. Ziggy47

    Ziggy47

    Joined:
    Aug 4, 2021
    Posts:
    4
    To run something on UI thread in hololens, you do

    Code (CSharp):
    1. #if !UNITY_EDITOR && UNITY_WSA      
    2.         UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
    3.         {
    4.             //Example code
    5.             UnityEngine.WSA.Launcher.LaunchUri(uri, false);
    6.         }, false);
    7. #endif
     
  4. Ziggy47

    Ziggy47

    Joined:
    Aug 4, 2021
    Posts:
    4
    However documentation says LaunchUriForResultsAsync is only supported with WinRT which Hololens doesnt have yet. Have you found a workaround by any chance?
     
  5. Di_o

    Di_o

    Joined:
    May 10, 2016
    Posts:
    62
    How do I find out the URI of a specific application?