Walkthrough: Using Windows 8 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.
Here’s a quick protocol demo
Not just any ole protocol
MSDN: Here is an alphabetic list of URI scheme names that you cannot enter into the package manifest because they are either reserved or forbidden: Application.manifest, Application.reference, Batfile, BLOB, Cerfile,Chm.file, Cmdfile, Comfile, Cplfile, Dllfile, Drvfile, Exefile, Explorer.AssocActionId. BurnSelection,Explorer. AssocActionId.CloseSession, Explorer.AssocActionId. EraseDisc, Explorer.AssocActionId. ZipSelection,Explorer. AssocProtocol.search-ms, Explorer.BurnSelection, Explorer.CloseSession, Explorer.EraseDisc, Explorer.ZipSelection, FILE, Fonfile, Hlpfile, Htafile, Inffile , Insfile, InternetShortcut, Jsefile, Lnkfile,Microsoft.PowerShellScript.1, MS-accountpictureprovider, Ms-appdata, Ms-appx, MS-AUTOPLAY, Msi.Package,Msi.Patch, Ms-windows-store, Ocxfile, Piffile, Regfile, Scrfile, Scriptletfile, Shbfile, Shcmdfile, Shsfile, SMB,Sysfile, Ttffile, Unknown, userTileProvider,vbefile, Vbsfile, Windows.gadget, Wsffile, Wsfile, Wshfile.
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:
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:
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.
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.
Best of luck!
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)