Search code examples
c#windows-phone-8uriurl-schemecustom-url

Can't launch windows phone app with a custom url scheme


I'm trying to write an app that should be launched automatically when the user clicks on a link with a specific url (that should be something like "myscheme://myurl")

I followed the instructions on this link http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987(v=vs.105).aspx However, it doesn't work

Here's what my code looks like

In the WMAppManifest.xml file I added this after the tokens

<Extensions>
  <Protocol Name="myscheme"
            NavUriFragment="encodedLaunchUri=%s"
            TaskID="_default" />
</Extensions>

I then created a file that I named AssociationUriMapper.cs and that contains

using System;
using System.Windows.Navigation;

namespace PhoneApp3
{
    class AssociationUriMapper : UriMapperBase
    {
        private string tempUri;

        public override Uri MapUri(Uri uri)
        {
            tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());

            //URI association for my scheme
            if (tempUri.Contains("myscheme:"))
            {
                return new Uri("/MainPage.xaml");
           }

            //else return
            return uri;
        }
    }
}

Then in the App.xaml.cs I added this line after the "rootframe.navigated"

// Assign the URI mapper to the frame
RootFrame.UriMapper = new AssociationUriMapper();

Now according to what I understood of the link that I included from msdn, if I go to internet explorer in the Windows Phone Simulator and type anything like "myscheme://something" it should automatically launch my app (even if the app does nothing provided that I don't manage to really use the url for now, I just want it to open my app)

I don't really now what to do, I found some other tutorials that explain exactly the same thing so I don't understand why my code doesn't work...

(BTW, sorry if I made grammar or spelling mistakes, English is not my mother tongue)


Solution

  • You can take a look at this tutorial.

    Here is a quote from it:

    What will trigger your URI association and launch your app: Get the URI from NFC tag. Get the URI by mail. Click on a HTML link containing the URI. Webpage redirection with a custom protocol. Get the URI from NFC device sharing an URI.

    And another one:

    What will NOT trigger your URI association and launch your app: Enter directly the URI in the Web Browser. Scan a QR code from Bing search.

    So, entering the URI in the browser does NOT work. To test how your app behaves when launched from another app, you can download Shortcuts, make a shortcut to custom URI, and enter the URI you want to test there.

    Disclaimer: I work at Enless Soft and Shortcuts is one of our apps.