Search Unity

Get shared files when the Unity UWP D3D IL2CPP app is launched by another UWP non Unity app

Discussion in 'Scripting' started by yaqinh0818, Mar 8, 2019.

  1. yaqinh0818

    yaqinh0818

    Joined:
    Mar 4, 2017
    Posts:
    5
    Hi guys,

    I am using the Unity engine to develop a HoloLens UWP D3D IL2CPP app that load files from another app.

    The situation is that another UWP app (non-Unity) wants to launch this Unity app and pass files to this Unity app.

    Let's call the non-Unity app as "sender app" and the Unity app I am developing as "receiver app"

    So in the sender app, the code for launching the receiver app is as following:

    Code (CSharp):
    1.  
    2.        var launchUri = new Uri("com.receiverapp.showfile:?FileId=232");
    3.        var options = new Windows.System.LauncherOptions
    4.        {
    5.               DisplayApplicationPicker = false,
    6.               TargetApplicationPackageFamilyName = "06074e70-0d41-49c7-8f99-71586afey5d2_tpswyvgiomn7t",
    7.        };
    8.        var storageFile = await GetStorageFileAsync(filename);
    9.        var token = SharedStorageAccessManager.AddFile(storageFile);
    10.        var inputData = new ValueSet();
    11.        inputData.Add("Token", token);
    12.        var success = await Launcher.LaunchUriAsync(launchUri, options, inputData);
    13.  
    So my question is in my receiver app (Unity app), how could I get the shared files when my receiver app is launched/activated?

    If my receiver app is non-Unity UWP C# solution, then what I could do is the following to achieve my goal:

    Step1 In App.xaml.cs in Visual Studio solution

    Code (CSharp):
    1. protected override void OnActivated(IActivatedEventArgs args)
    2.         {
    3.             Frame rootFrame = CreateRootFrame(ApplicationExecutionState.NotRunning);
    4.             if (args.Kind == ActivationKind.Protocol)
    5.             {
    6.                 var protocolArgs = args as ProtocolActivatedEventArgs;
    7.                 var inputData = protocolArgs.Data;
    8.                 string tokens = "";
    9.                 for (int tokenIndex = 0; ; ++tokenIndex)
    10.                 {
    11.                     if (inputData.TryGetValue($"Token{tokenIndex}", out object tokenValue))
    12.                     {
    13.                         if (tokens.Length > 0)
    14.                         {
    15.                             tokens += '|';
    16.                         }
    17.                         tokens += (string)tokenValue;
    18.                     }
    19.                     else
    20.                     {
    21.                         break;
    22.                     }
    23.                 }
    24.                 rootFrame.Navigate(typeof(MainPage), protocolArgs.Uri.AbsoluteUri + "|" + tokens);
    25.             }
    26. }
    Step 2 Get the shared files

    Code (CSharp):
    1. var storageFile = await SharedStorageAccessManager.RedeemTokenForFileAsync(token);
    2.                                 StorageApplicationPermissions.FutureAccessList.Add(storageFile, storageFile.Path);
    3.  
    4.                                 if (files.Length > 0)
    5.                                 {
    6.                                     files += ',';
    7.                                 }
    8.                                 files += storageFile.Path;
    9.                                 var readError = await ReadInputFileAsync(storageFile);

    Is it possible to do the exact same thing in the receiver app (Unity UWP D3D IL2CPP app)? If so? How? It would be good to show me some example code. Thanks!
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    You can do it in D3D app too. The code would be identical - D3D also has OnActivated method.
     
  3. yaqinh0818

    yaqinh0818

    Joined:
    Mar 4, 2017
    Posts:
    5