Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding UriMapper for WindowsPhone in Universal Application

I'm struggling creating an universal app out of an existing windows phone 8.1 app. I used the AssociationUriMapper as described here and I can't find a way to use this in the universal app. The System.Windows.Navigation namespace does not exist and therefore I can't override the UriMapperBase.

Anyone know where this goes wrong and what I have to do to keep the functionality even in an universal app (without offering the same feature to windows 8.1 app)?

like image 635
malte Avatar asked Mar 24 '26 05:03

malte


1 Answers

How apps handle Uris on launch has changed a lot since Windows Phone 8. Previously, the app would get passed a Uri which require a lot of parsing to be of any use - hence the need for a UriMapper, which Microsoft provides.

For Windows Phone 8.1 and Windows 8.1 (ie. Universal XAML apps), app activation is handled (by OpenFilePicker, ShareTarget, Protocol, etc) is handled by the OnActivated method...

protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.Protocol)
    {
        ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;

    // TODO: Handle URI activation
    // The received URI is eventArgs.Uri.AbsoluteUri
    }
}

Source: official MSDN documentation

After determining the ActivationKind and casting to the right EventArgs type, it's then just a matter of parsing the parameters of the data.

There's also an example Universal app on that page which details a few of these scenarios.

like image 195
Neil Turner Avatar answered Mar 26 '26 19:03

Neil Turner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!