Protocol activation, what is it? Well, when you run “http:{something}” you expect a browser to launch, right? When you type “mailto:{something}” you expect a mail client to launch, right? What if you could create “custom:{something}” that launched your app? That’s custom protocol activation!

MSDN: Windows allows an app to register to become the default handler for a certain URI scheme name. Both desktop and Windows Store apps can register to be a default handler for a URI scheme name. If the user chooses your app as the default handler for a URI scheme name, your app will be activated every time that type of URI is launched. You should only register for a URI scheme name if you expect to handle all URI launches for that type of URI scheme. If you do choose to register for a URI scheme name it is important that you provide the end user with the functionality that is expected when your app is activated for that URI scheme. For example an app that registers for the mailto: URI scheme name should open to a new e-mail message so that the user can compose a new e-mail. For more info on file associations see Guidelines and checklist for file types and URIs.

Some find things to try

The Bing Maps app that comes installed on Windows 8 supports protocol activation. This means you can create shortcuts into it. It also means you can leverage it from your application. In fact many apps that include the Bing Maps control, really shouldn’t. Try running this:

bingmaps:?q=coffee&where=Omaha

Application Manifest

MSDN: The file type and protocol association model has changed in Windows 8. Apps are no longer able to programmatically set themselves as the default handler for a file type or protocol. Instead, now the user always controls what the default handler is for a file type or protocol.

That screen above is the application manifest. It’s on the declarations tab where we can add the “protocol” declaration.

MSDN: Your app can use existing protocols for communication, such as mailto, or create a custom protocol. The protocol activation extension enables you to define a custom protocol or register to handle an existing protocol.

Let’s take it to another level!

In the video above, one key operation was for my application to call a Uri. To do this in C#, we use LaunchUriAsync and pass in the Uri we want to launch. Like this:

Security considerations

MSDN: As noted above, the URL that is passed to an application protocol handler might be broken across multiple parameters. Malicious parties could use additional quotation marks or backslash characters to pass additional command-line parameters. For this reason, application protocol handlers should assume that any parameters on the command line could come from malicious parties, and carefully validate them. Applications that could initiate dangerous actions based on external data must first confirm those actions with the user. In addition, handling applications should be tested with URLs that are overly long or contain unexpected (or undesirable) character sequences.

Conclusion

Why not? Protocol activation is just another cool way to activate your app. It’s easy (I hope that’s obvious) and doesn’t cost you a thing. And, maybe, just maybe, you can do even more than you originally dreamed with your app – engage imagination.