Mayer M
Mayer M

Reputation: 243

How to use parameters from Uri in destination App?

I need to launch an app with a boolean parameter from another app that gets such parameter. Both are apps installed in Windows. The purpose of the parameter is to enable/disable a control in the launched app.

I found a way to launch the app with the parameter (being the parameter like "?MyParameter=true"). I'm using Windows.System.Launcher.LaunchUriAsync(myUriWithParameters); in app A, and it fires successfully, but don't have any idea how to get that parameter from the new app. Is this possible? how can I do it?

Thanks in advance.

Upvotes: 0

Views: 685

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

The OnActivated event handler receives all activation events. The Kind property indicates the type of activation event. This example is set up to handle Protocol activation events.

So you could get your parameter in eventArgs.Uri.AbsolutePath.

protected override void OnActivated(IActivatedEventArgs args)
  {
      if (args.Kind == ActivationKind.Protocol)
      {
         ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
         var parm = eventArgs.Uri.AbsolutePath;
         // TODO: Handle URI activation
         // The received URI is eventArgs.Uri.AbsoluteUri
      }
   }

Upvotes: 1

Related Questions